• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 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.dialer.precall.impl;
18 
19 import android.app.Activity;
20 import android.app.KeyguardManager;
21 import android.os.Bundle;
22 import android.support.annotation.Nullable;
23 import android.view.WindowManager.LayoutParams;
24 
25 /** A transparent activity to host dialogs for {@link PreCallCoordinatorImpl} */
26 public class PreCallActivity extends Activity {
27 
28   private PreCallCoordinatorImpl preCallCoordinator;
29 
30   @Override
onCreate(@ullable Bundle savedInstanceState)31   public void onCreate(@Nullable Bundle savedInstanceState) {
32     super.onCreate(savedInstanceState);
33     preCallCoordinator = new PreCallCoordinatorImpl(this);
34     preCallCoordinator.onCreate(getIntent(), savedInstanceState);
35     if (getSystemService(KeyguardManager.class).isKeyguardLocked()) {
36       // Note:
37       //
38       // Flag LayoutParams.FLAG_TURN_SCREEN_ON was deprecated in O_MR1, but calling the new API
39       // setTurnScreenOn(true) doesn't give us the expected behavior.
40       //
41       // Calling setTurnScreenOn(true) alone doesn't turn on the screen when the device is locked.
42       // We must also call KeyguardManager#requestDismissKeyguard, which will bring up the lock
43       // screen for the user to enter their credentials.
44       //
45       // If the Keyguard is not secure or the device is currently in a trusted state, calling
46       // requestDismissKeyguard will immediately dismiss the Keyguard without any user interaction.
47       // However, the lock screen will still pop up before it quickly disappears.
48       //
49       // If the Keyguard is secure and the device is not in a trusted state, the device will show
50       // the lock screen and wait for the user's credentials.
51       //
52       // Therefore, to avoid showing the lock screen, we will continue using the deprecated flag in
53       // O_MR1 and later Android versions.
54       //
55       // Flag LayoutParams.FLAG_SHOW_WHEN_LOCKED was also deprecated in O_MR1, and the new API
56       // setShowWhenLocked(boolean) works. However, as the purpose of the two new APIs is to prevent
57       // an unintentional double life-cycle event, only using one is ineffective.
58       //
59       // Therefore, to simplify code and make testing easier, we will also keep using
60       // LayoutParams.FLAG_SHOW_WHEN_LOCKED.
61       getWindow().addFlags(LayoutParams.FLAG_SHOW_WHEN_LOCKED | LayoutParams.FLAG_TURN_SCREEN_ON);
62     }
63   }
64 
65   @Override
onRestoreInstanceState(Bundle savedInstanceState)66   protected void onRestoreInstanceState(Bundle savedInstanceState) {
67     super.onRestoreInstanceState(savedInstanceState);
68     preCallCoordinator.onRestoreInstanceState(savedInstanceState);
69   }
70 
71   @Override
onResume()72   public void onResume() {
73     super.onResume();
74     preCallCoordinator.onResume();
75   }
76 
77   @Override
onPause()78   public void onPause() {
79     super.onPause();
80     preCallCoordinator.onPause();
81   }
82 
83   @Override
onSaveInstanceState(Bundle outState)84   public void onSaveInstanceState(Bundle outState) {
85     super.onSaveInstanceState(outState);
86     preCallCoordinator.onSaveInstanceState(outState);
87   }
88 }
89