• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 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.tv.provision;
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.net.wifi.WifiManager;
24 import android.net.wifi.WifiConfiguration;
25 import android.os.Bundle;
26 import android.os.SystemProperties;
27 import android.os.UserHandle;
28 import android.os.UserManager;
29 import android.provider.Settings;
30 import android.util.Log;
31 
32 /**
33  * Application that sets the provisioned bit, like SetupWizard does.
34  */
35 public class DefaultActivity extends Activity {
36 
37     private static final String TV_USER_SETUP_COMPLETE = "tv_user_setup_complete";
38     private static final String TAG = "TvProvision";
39     private static final int ADD_NETWORK_FAIL = -1;
40     @Override
onCreate(Bundle icicle)41     protected void onCreate(Bundle icicle) {
42         super.onCreate(icicle);
43 
44         // Add a persistent setting to allow other apps to know the device has been provisioned.
45         if (!isRestrictedUser()) {
46             Settings.Global.putInt(getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 1);
47         }
48         Settings.Secure.putInt(getContentResolver(), Settings.Secure.USER_SETUP_COMPLETE, 1);
49         Settings.Secure.putInt(getContentResolver(), TV_USER_SETUP_COMPLETE, 1);
50         if (SystemProperties.get("ro.boot.qemu").equals("1")) {
51           // Emulator-only: Enable USB debugging and adb
52           Settings.Global.putInt(getContentResolver(), Settings.Global.ADB_ENABLED, 1);
53           // Add network with SSID "AndroidWifi"
54           WifiConfiguration config = new WifiConfiguration();
55           config.SSID = "\"AndroidWifi\"";
56           config.setSecurityParams(WifiConfiguration.SECURITY_TYPE_OPEN);
57           WifiManager mWifiManager = getApplicationContext().getSystemService(WifiManager.class);
58           int netId = mWifiManager.addNetwork(config);
59           if (netId == ADD_NETWORK_FAIL || mWifiManager.enableNetwork(netId, true)) {
60               Log.e(TAG, "Unable to add Wi-Fi network AndroidWifi.");
61           }
62         }
63 
64         // remove this activity from the package manager.
65         PackageManager pm = getPackageManager();
66         ComponentName name = new ComponentName(this, DefaultActivity.class);
67         pm.setComponentEnabledSetting(name, PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
68                 PackageManager.DONT_KILL_APP);
69 
70         // terminate the activity.
71         finish();
72     }
73 
isRestrictedUser()74     private boolean isRestrictedUser() {
75         UserManager userManager = (UserManager) getSystemService(Context.USER_SERVICE);
76         return userManager.isRestrictedProfile();
77     }
78 }
79 
80