• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2020 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 package com.android.provision;
17 
18 import android.content.ContentResolver;
19 import android.provider.Settings;
20 import android.util.Log;
21 
22 /**
23  * Utility helpers.
24  */
25 final class Utils {
26 
27     static final String TAG = "Provision";
28 
29     private static final String BASE_SETTINGS = "tmp_provision_";
30     static final String SETTINGS_PROVISION_DO_MODE = BASE_SETTINGS + "set_do";
31     static final String SETTINGS_PROVISION_DO_PKG = BASE_SETTINGS + "package";
32     static final String SETTINGS_PROVISION_DO_RECEIVER = BASE_SETTINGS + "receiver";
33     static final String SETTINGS_PROVISION_DO_CHECKSUM = BASE_SETTINGS + "checksum";
34     static final String SETTINGS_PROVISION_DO_DOWNLOAD_URL = BASE_SETTINGS + "download_url";
35     static final String SETTINGS_PROVISION_DO_DOWNLOAD_TRIGGER = BASE_SETTINGS + "trigger";
36 
37     // Values below should be merged as null / 0, but can be changed locally to make it easier
38     // to trigger device owner provisioning (see example below).
39     static final int DEFAULT_SETTINGS_PROVISION_DO_MODE = 0;
40     static final String DEFAULT_SETTINGS_PROVISION_DO_PKG = null;
41     static final String DEFAULT_SETTINGS_PROVISION_DO_RECEIVER = null;
42     static final int DEFAULT_SETTINGS_PROVISION_DO_DOWNLOAD_TRIGGER = 0;
43     static final String DEFAULT_SETTINGS_PROVISION_DO_CHECKSUM = null;
44     static final String DEFAULT_SETTINGS_PROVISION_DO_DOWNLOAD_URL = null;
45 
46     // Use these constants to trigger device owner provisioning using the TestDPC app (notice that
47     // it must be manually installed in the device).
48 //    static final int DEFAULT_SETTINGS_PROVISION_DO_MODE = 1;
49 //    static final String DEFAULT_SETTINGS_PROVISION_DO_PKG = "com.afwsamples.testdpc";
50 //    static final String DEFAULT_SETTINGS_PROVISION_DO_RECEIVER =
51 //            "com.afwsamples.testdpc.DeviceAdminReceiver";
52 //    static final int DEFAULT_SETTINGS_PROVISION_DO_DOWNLOAD_TRIGGER =
53 //            android.app.admin.DevicePolicyManager.PROVISIONING_TRIGGER_QR_CODE;
54 
55 
getSettings(ContentResolver resolver, String property, String overriddenValue)56     static String getSettings(ContentResolver resolver, String property,
57             String overriddenValue) {
58         if (overriddenValue != null) {
59             Log.w(TAG, "Using OVERRIDDEN value " + overriddenValue + " for property " + property);
60             return overriddenValue;
61         }
62         String value = Settings.Secure.getString(resolver, property);
63         Log.w(TAG, "Using value " + overriddenValue + " for property " + property);
64         return value;
65     }
66 
getSettings(ContentResolver resolver, String property, int overriddenValue)67     static int getSettings(ContentResolver resolver, String property,
68             int overriddenValue) {
69         if (overriddenValue != 0) {
70             Log.w(TAG, "Using OVERRIDDEN value " + overriddenValue + " for property " + property);
71             return overriddenValue;
72         }
73         int value = Settings.Secure.getInt(resolver, property, overriddenValue);
74         Log.w(TAG, "Using value " + overriddenValue + " for property " + property);
75         return value;
76     }
77 
Utils()78     private Utils() {
79         throw new UnsupportedOperationException("contains only static members");
80     }
81 }
82