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.provider.Settings; 27 import android.os.Bundle; 28 import android.os.RemoteException; 29 import android.os.ServiceManager; 30 import android.os.SystemProperties; 31 import android.os.Build; 32 import android.telephony.TelephonyManager; 33 import android.view.InputDevice; 34 35 /** 36 * Entry point for SDK SetupWizard. 37 * 38 */ 39 public class DefaultActivity extends Activity { 40 41 @Override onCreate(Bundle icicle)42 protected void onCreate(Bundle icicle) { 43 super.onCreate(icicle); 44 45 // Edit Settings only for Emulator 46 if (Build.IS_EMULATOR) { 47 // Set physical keyboard layout based on the system property set by emulator host. 48 String layoutName = SystemProperties.get("qemu.keyboard_layout"); 49 String deviceName = "qwerty2"; 50 InputDevice device = getKeyboardDevice(deviceName); 51 if (device != null && !layoutName.isEmpty()) { 52 setKeyboardLayout(device, layoutName); 53 } 54 // Add a persistent setting to allow other apps to know the device has been provisioned. 55 Settings.Global.putInt(getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 1); 56 57 Settings.Secure.putInt(getContentResolver(), Settings.Secure.USER_SETUP_COMPLETE, 1); 58 59 // Disables a dialog shown on adb install execution. 60 Settings.Global.putInt(getContentResolver(), Settings.Global.PACKAGE_VERIFIER_INCLUDE_ADB, 0); 61 62 // Enable the GPS. 63 // Not needed since this SDK will contain the Settings app. 64 Settings.Secure.putString(getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED, 65 LocationManager.GPS_PROVIDER); 66 67 // enable install from non market 68 Settings.Secure.putInt(getContentResolver(), Settings.Secure.INSTALL_NON_MARKET_APPS, 1); 69 70 Settings.Global.putInt(getContentResolver(), Settings.Global.ADB_ENABLED, 1); 71 72 TelephonyManager mTelephony = getApplicationContext().getSystemService(TelephonyManager.class); 73 mTelephony.setPreferredNetworkTypeBitmask(TelephonyManager.NETWORK_TYPE_BITMASK_NR); 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