2 * Copyright (C) 2016 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.android.settings;
19 import android.app.Activity;
20 import android.content.Intent;
21 import android.net.ConnectivityManager;
22 import android.os.Bundle;
23 import android.os.ResultReceiver;
24 import android.os.UserHandle;
25 import android.util.Log;
28 * Activity which acts as a proxy to the tether provisioning app for sanity checks and permission
29 * restrictions. Specifically, the provisioning apps require
30 * {@link android.permission.CONNECTIVITY_INTERNAL}, while this activity can be started by a caller
31 * with {@link android.permission.TETHER_PRIVILEGED}.
33 public class TetherProvisioningActivity extends Activity {
34 private static final int PROVISION_REQUEST = 0;
35 private static final String TAG = "TetherProvisioningAct";
36 private static final String EXTRA_TETHER_TYPE = "TETHER_TYPE";
37 private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
38 private ResultReceiver mResultReceiver;
41 public void onCreate(Bundle savedInstanceState) {
42 super.onCreate(savedInstanceState);
44 mResultReceiver = (ResultReceiver)getIntent().getParcelableExtra(
45 ConnectivityManager.EXTRA_PROVISION_CALLBACK);
47 // TODO: Move isProvisioningNeededButUnavailable into ConnectivityManager and check
48 // it here to short-circuit and fail.
50 int tetherType = getIntent().getIntExtra(ConnectivityManager.EXTRA_ADD_TETHER_TYPE,
51 ConnectivityManager.TETHERING_INVALID);
52 String[] provisionApp = getResources().getStringArray(
53 com.android.internal.R.array.config_mobile_hotspot_provision_app);
55 Intent intent = new Intent(Intent.ACTION_MAIN);
56 intent.setClassName(provisionApp[0], provisionApp[1]);
57 intent.putExtra(EXTRA_TETHER_TYPE, tetherType);
59 Log.d(TAG, "Starting provisioning app: " + provisionApp[0] + "." + provisionApp[1]);
61 startActivityForResultAsUser(intent, PROVISION_REQUEST, UserHandle.CURRENT);
65 public void onActivityResult(int requestCode, int resultCode, Intent intent) {
66 super.onActivityResult(requestCode, resultCode, intent);
67 if (requestCode == PROVISION_REQUEST) {
68 if (DEBUG) Log.d(TAG, "Got result from app: " + resultCode);
69 int result = resultCode == Activity.RESULT_OK ?
70 ConnectivityManager.TETHER_ERROR_NO_ERROR :
71 ConnectivityManager.TETHER_ERROR_PROVISION_FAILED;
72 mResultReceiver.send(result, null);