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.permissioncontroller.permission.ui;
18 
19 import static android.view.WindowManager.LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS;
20 
21 import android.content.Intent;
22 import android.os.Bundle;
23 import android.view.MenuItem;
24 
25 import androidx.annotation.NonNull;
26 
27 import com.android.permissioncontroller.DeviceUtils;
28 import com.android.permissioncontroller.permission.ui.handheld.ReviewOngoingUsageWrapperFragment;
29 import com.android.permissioncontroller.permission.ui.handheld.dashboard.UtilsKt;
30 
31 /**
32  * A dialog listing the currently uses of camera, microphone, and location.
33  */
34 public final class ReviewOngoingUsageActivity extends SettingsActivity {
35 
36     // Number of milliseconds in the past to look for accesses if nothing was specified.
37     private static final long DEFAULT_MILLIS = 5000;
38 
39     @Override
onCreate(Bundle savedInstanceState)40     protected void onCreate(Bundle savedInstanceState) {
41         super.onCreate(savedInstanceState);
42 
43         if (!UtilsKt.shouldShowCameraMicIndicators() && !UtilsKt.shouldShowLocationIndicators()) {
44             finishAfterTransition();
45             return;
46         }
47 
48         getWindow().addSystemFlags(SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS);
49 
50         long numMillis = getIntent().getLongExtra(Intent.EXTRA_DURATION_MILLIS, DEFAULT_MILLIS);
51         getSupportFragmentManager().beginTransaction().replace(android.R.id.content,
52                 ReviewOngoingUsageWrapperFragment.newInstance(numMillis)).commit();
53     }
54 
55 
56     @Override
onOptionsItemSelected(@onNull MenuItem item)57     public boolean onOptionsItemSelected(@NonNull MenuItem item) {
58         switch (item.getItemId()) {
59             case android.R.id.home:
60                 // in automotive mode, there's no system wide back button, so need to add that
61                 if (DeviceUtils.isAuto(this)) {
62                     onBackPressed();
63                 } else {
64                     finishAfterTransition();
65                 }
66                 return true;
67             default:
68                 return super.onOptionsItemSelected(item);
69         }
70     }
71 }