• 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 static com.android.provision.Utils.DEFAULT_SETTINGS_PROVISION_DO_CHECKSUM;
19 import static com.android.provision.Utils.DEFAULT_SETTINGS_PROVISION_DO_DOWNLOAD_TRIGGER;
20 import static com.android.provision.Utils.DEFAULT_SETTINGS_PROVISION_DO_DOWNLOAD_URL;
21 import static com.android.provision.Utils.DEFAULT_SETTINGS_PROVISION_DO_PKG;
22 import static com.android.provision.Utils.DEFAULT_SETTINGS_PROVISION_DO_RECEIVER;
23 import static com.android.provision.Utils.SETTINGS_PROVISION_DO_CHECKSUM;
24 import static com.android.provision.Utils.SETTINGS_PROVISION_DO_DOWNLOAD_TRIGGER;
25 import static com.android.provision.Utils.SETTINGS_PROVISION_DO_DOWNLOAD_URL;
26 import static com.android.provision.Utils.SETTINGS_PROVISION_DO_PKG;
27 import static com.android.provision.Utils.SETTINGS_PROVISION_DO_RECEIVER;
28 import static com.android.provision.Utils.getSettings;
29 
30 import android.content.ComponentName;
31 import android.content.ContentResolver;
32 
33 import java.util.Objects;
34 
35 /**
36  * Info about a Device Policy Controller app.
37  */
38 final class DpcInfo {
39 
40     public final String packageName;
41     private final String mReceiverName;
42     public final String checkSum;
43     public final String downloadUrl;
44     public final int trigger;
45 
DpcInfo(ContentResolver resolver)46     DpcInfo(ContentResolver resolver) {
47         this(getSettings(resolver, SETTINGS_PROVISION_DO_PKG, DEFAULT_SETTINGS_PROVISION_DO_PKG),
48                 getSettings(resolver, SETTINGS_PROVISION_DO_RECEIVER,
49                         DEFAULT_SETTINGS_PROVISION_DO_RECEIVER),
50                 getSettings(resolver, SETTINGS_PROVISION_DO_CHECKSUM,
51                         DEFAULT_SETTINGS_PROVISION_DO_CHECKSUM),
52                 getSettings(resolver, SETTINGS_PROVISION_DO_DOWNLOAD_URL,
53                         DEFAULT_SETTINGS_PROVISION_DO_DOWNLOAD_URL),
54                 getSettings(resolver, SETTINGS_PROVISION_DO_DOWNLOAD_TRIGGER,
55                         DEFAULT_SETTINGS_PROVISION_DO_DOWNLOAD_TRIGGER));
56     }
57 
DpcInfo(String packageName, String receiverName, String checkSum, String downloadUrl, int trigger)58     private DpcInfo(String packageName, String receiverName, String checkSum, String downloadUrl,
59             int trigger) {
60         this.packageName = Objects.requireNonNull(packageName,
61                 "packageName (" + SETTINGS_PROVISION_DO_PKG + ") cannot be null");
62         this.mReceiverName = Objects.requireNonNull(receiverName,
63                 "receiverName(" + SETTINGS_PROVISION_DO_RECEIVER + ") cannot be null");
64         this.checkSum = checkSum;
65         this.downloadUrl = downloadUrl;
66         this.trigger = trigger;
67     }
68 
69     /***
70      * Gets the name of the admin receiver.
71      */
getReceiverComponentName()72     public ComponentName getReceiverComponentName() {
73         return new ComponentName(packageName, mReceiverName);
74     }
75 
76     @Override
toString()77     public String toString() {
78         return "DpcInfo[package=" + packageName
79                 + ", receiver=" + getReceiverComponentName()
80                 + ", checkSum=" + checkSum
81                 + ", downloadUrl=" + downloadUrl
82                 + ", trigger=" + trigger
83                 + "]";
84     }
85 }
86