1 /* 2 * Copyright (C) 2008 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.sdksetup; 18 19 import android.app.Activity; 20 import android.content.ComponentName; 21 import android.content.Context; 22 import android.content.pm.PackageManager; 23 import android.hardware.input.InputManager; 24 import android.hardware.input.KeyboardLayout; 25 import android.location.LocationManager; 26 import android.os.Bundle; 27 import android.os.RemoteException; 28 import android.os.ServiceManager; 29 import android.os.SystemProperties; 30 import android.os.Build; 31 import android.provider.Settings; 32 import android.view.InputDevice; 33 34 /** 35 * Entry point for SDK SetupWizard. 36 * 37 */ 38 public class DefaultActivity extends Activity { 39 40 @Override onCreate(Bundle icicle)41 protected void onCreate(Bundle icicle) { 42 super.onCreate(icicle); 43 44 // Edit Settings only for Emulator 45 if (Build.IS_EMULATOR) { 46 // Set physical keyboard layout based on the system property set by emulator host. 47 String layoutName = SystemProperties.get("qemu.keyboard_layout"); 48 String deviceName = "qwerty2"; 49 InputDevice device = getKeyboardDevice(deviceName); 50 if (device != null && !layoutName.isEmpty()) { 51 setKeyboardLayout(device, layoutName); 52 } 53 // Add a persistent setting to allow other apps to know the device has been provisioned. 54 Settings.Global.putInt(getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 1); 55 56 Settings.Secure.putInt(getContentResolver(), Settings.Secure.USER_SETUP_COMPLETE, 1); 57 58 // Disables a dialog shown on adb install execution. 59 Settings.Global.putInt(getContentResolver(), Settings.Global.PACKAGE_VERIFIER_INCLUDE_ADB, 0); 60 61 // Enable the GPS. 62 // Not needed since this SDK will contain the Settings app. 63 Settings.Secure.putString(getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED, 64 LocationManager.GPS_PROVIDER); 65 66 // enable install from non market 67 Settings.Secure.putInt(getContentResolver(), Settings.Secure.INSTALL_NON_MARKET_APPS, 1); 68 69 Settings.Global.putInt(getContentResolver(), Settings.Global.ADB_ENABLED, 1); 70 71 // Disable offload wifi tethering 72 Settings.Global.putInt(getContentResolver(), Settings.Global.TETHER_OFFLOAD_DISABLED, 1); 73 74 } 75 76 // remove this activity from the package manager. 77 PackageManager pm = getPackageManager(); 78 ComponentName name = new ComponentName(this, DefaultActivity.class); 79 pm.setComponentEnabledSetting(name, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, 0); 80 81 // terminate the activity. 82 finish(); 83 } 84 getKeyboardDevice(String keyboardDeviceName)85 private InputDevice getKeyboardDevice(String keyboardDeviceName) { 86 int[] deviceIds = InputDevice.getDeviceIds(); 87 88 for (int deviceId : deviceIds) { 89 InputDevice inputDevice = InputDevice.getDevice(deviceId); 90 if (inputDevice != null 91 && inputDevice.supportsSource(InputDevice.SOURCE_KEYBOARD) 92 && inputDevice.getName().equals(keyboardDeviceName)) { 93 return inputDevice; 94 } 95 } 96 return null; 97 } 98 setKeyboardLayout(InputDevice keyboardDevice, String layoutName)99 private void setKeyboardLayout(InputDevice keyboardDevice, String layoutName) { 100 InputManager im = InputManager.getInstance(); 101 102 KeyboardLayout[] keyboardLayouts = 103 im.getKeyboardLayoutsForInputDevice(keyboardDevice.getIdentifier()); 104 105 for (KeyboardLayout keyboardLayout : keyboardLayouts) { 106 if (keyboardLayout.getDescriptor().endsWith(layoutName)) { 107 im.setCurrentKeyboardLayoutForInputDevice( 108 keyboardDevice.getIdentifier(), keyboardLayout.getDescriptor()); 109 return; 110 } 111 } 112 } 113 } 114 115