1 /* 2 * Copyright (C) 2024 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.devicelockcontroller.activities; 18 19 import android.app.Activity; 20 import android.content.Intent; 21 import android.os.Bundle; 22 23 import androidx.annotation.Nullable; 24 25 import com.android.devicelockcontroller.policy.DevicePolicyController; 26 import com.android.devicelockcontroller.policy.PolicyObjectsProvider; 27 import com.android.devicelockcontroller.util.LogUtil; 28 29 import com.google.common.util.concurrent.FutureCallback; 30 import com.google.common.util.concurrent.Futures; 31 32 /** 33 * Activity that handles home action when the device is locked. 34 * Uses the existing intent resolution logic to trampoline to the locked activity. 35 */ 36 public final class LockedHomeActivity extends Activity { 37 private static final String TAG = LockedHomeActivity.class.getSimpleName(); 38 39 @Override onCreate(@ullable Bundle savedInstanceState)40 public void onCreate(@Nullable Bundle savedInstanceState) { 41 super.onCreate(savedInstanceState); 42 43 DevicePolicyController devicePolicyController = 44 ((PolicyObjectsProvider) getApplicationContext()).getPolicyController(); 45 Futures.addCallback(devicePolicyController.getLaunchIntentForCurrentState(), 46 new FutureCallback<>() { 47 @Override 48 public void onSuccess(Intent intent) { 49 if (intent != null) { 50 startActivity(intent); 51 } 52 finish(); 53 } 54 55 @Override 56 public void onFailure(Throwable t) { 57 LogUtil.e(TAG, "Failed to acquire launch intent for current state", t); 58 } 59 }, getMainExecutor()); 60 } 61 } 62