• 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 
17 package com.android.tv.settings.startup;
18 
19 import android.app.Activity;
20 import android.content.Intent;
21 import android.content.pm.PackageManager;
22 import android.content.pm.ResolveInfo;
23 import android.text.TextUtils;
24 import android.util.Log;
25 
26 import androidx.annotation.NonNull;
27 
28 import com.android.tv.settings.R;
29 
30 import java.util.List;
31 
32 /**
33  * Implementation of {@link StartupVerificationFeatureProvider} that can be enabled using runtime
34  * resource overlay.
35  */
36 public class StartupVerificationFeatureProviderImplX implements StartupVerificationFeatureProvider {
37 
38     private static final String TAG = "StartupVerifyFeatureX";
39 
40     @Override
startStartupVerificationActivityForResult( @onNull Activity activity, int requestCode)41     public boolean startStartupVerificationActivityForResult(
42             @NonNull Activity activity, int requestCode) {
43         final String startupVerificationAction =
44                 activity.getString(R.string.startup_verification_action);
45         final String startupVerificationPackage =
46                 activity.getString(R.string.startup_verification_package);
47         if (TextUtils.isEmpty(startupVerificationAction)
48                 || TextUtils.isEmpty(startupVerificationPackage)) {
49             Log.e(TAG, "Activity for handling startup verification is undefined.");
50             return false;
51         }
52         Intent intent =
53                 new Intent(startupVerificationAction).setPackage(startupVerificationPackage);
54         List<ResolveInfo> intentHandlingActivities =
55                 activity.getPackageManager().queryIntentActivities(
56                         intent, PackageManager.MATCH_DEFAULT_ONLY);
57         for (ResolveInfo info : intentHandlingActivities) {
58             if (info.activityInfo != null && info.activityInfo.enabled) {
59                 Log.v(TAG, "Starting startup verification activity.");
60                 activity.startActivityForResult(intent, requestCode);
61                 return true;
62             }
63         }
64         Log.v(TAG, "Missing Activity for handling startup verification.");
65         return false;
66     }
67 }
68