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