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.v31.ReviewOngoingUsageWrapperFragment;
29 import com.android.permissioncontroller.permission.utils.KotlinUtils;
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 (!KotlinUtils.INSTANCE.shouldShowCameraMicIndicators()
44                 && !KotlinUtils.INSTANCE.shouldShowLocationIndicators()) {
45             finishAfterTransition();
46             return;
47         }
48 
49         getWindow().addSystemFlags(SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS);
50 
51         long numMillis = getIntent().getLongExtra(Intent.EXTRA_DURATION_MILLIS, DEFAULT_MILLIS);
52         getSupportFragmentManager().beginTransaction().replace(android.R.id.content,
53                 ReviewOngoingUsageWrapperFragment.newInstance(numMillis)).commit();
54     }
55 
56 
57     @Override
onOptionsItemSelected(@onNull MenuItem item)58     public boolean onOptionsItemSelected(@NonNull MenuItem item) {
59         switch (item.getItemId()) {
60             case android.R.id.home:
61                 // in automotive mode, there's no system wide back button, so need to add that
62                 if (DeviceUtils.isAuto(this)) {
63                     onBackPressed();
64                 } else {
65                     finishAfterTransition();
66                 }
67                 return true;
68             default:
69                 return super.onOptionsItemSelected(item);
70         }
71     }
72 }