• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 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.settings.deviceinfo.firmwareversion;
18 
19 import android.content.Context;
20 import android.content.Intent;
21 import android.content.pm.PackageManager;
22 import android.net.Uri;
23 import android.text.TextUtils;
24 import android.util.Log;
25 
26 import androidx.preference.Preference;
27 
28 import com.android.settings.core.BasePreferenceController;
29 import com.android.settingslib.DeviceInfoUtils;
30 
31 public class SecurityPatchLevelPreferenceController extends BasePreferenceController {
32 
33     private static final String TAG = "SecurityPatchCtrl";
34     private static final Uri INTENT_URI_DATA = Uri.parse(
35             "https://source.android.com/security/bulletin/");
36 
37     private final PackageManager mPackageManager;
38     private final String mCurrentPatch;
39 
SecurityPatchLevelPreferenceController(Context context, String key)40     public SecurityPatchLevelPreferenceController(Context context, String key) {
41         super(context, key);
42         mPackageManager = mContext.getPackageManager();
43         mCurrentPatch = DeviceInfoUtils.getSecurityPatch();
44     }
45 
46     @Override
getAvailabilityStatus()47     public int getAvailabilityStatus() {
48         return !TextUtils.isEmpty(mCurrentPatch)
49                 ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
50     }
51 
52     @Override
getSummary()53     public CharSequence getSummary() {
54         return mCurrentPatch;
55     }
56 
57     @Override
handlePreferenceTreeClick(Preference preference)58     public boolean handlePreferenceTreeClick(Preference preference) {
59         if (!TextUtils.equals(preference.getKey(), getPreferenceKey())) {
60             return false;
61         }
62 
63         final Intent intent = new Intent();
64         intent.setAction(Intent.ACTION_VIEW);
65         intent.setData(INTENT_URI_DATA);
66         if (mPackageManager.queryIntentActivities(intent, 0).isEmpty()) {
67             // Don't send out the intent to stop crash
68             Log.w(TAG, "queryIntentActivities() returns empty");
69             return true;
70         }
71 
72         mContext.startActivity(intent);
73         return true;
74     }
75 }
76