1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
package it.niedermann.owncloud.notes;
import android.app.KeyguardManager;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.WindowManager;
import androidx.annotation.Nullable;
import androidx.preference.PreferenceManager;
import it.niedermann.owncloud.notes.branding.BrandedActivity;
import it.niedermann.owncloud.notes.exception.ExceptionHandler;
public abstract class LockedActivity extends BrandedActivity {
private static final String TAG = LockedActivity.class.getSimpleName();
private static final int REQUEST_CODE_UNLOCK = 100;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Thread.currentThread().setUncaughtExceptionHandler(new ExceptionHandler(this));
if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean(getString(R.string.pref_key_prevent_screen_capture), false)) {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE);
}
if (isTaskRoot()) {
askToUnlock();
}
}
@Override
protected void onResume() {
super.onResume();
if (!isTaskRoot()) {
askToUnlock();
}
}
@Override
protected void onStop() {
super.onStop();
if (isTaskRoot()) {
NotesApplication.updateLastInteraction();
}
}
@Override
public void onBackPressed() {
super.onBackPressed();
NotesApplication.updateLastInteraction();
}
@Override
public void startActivityForResult(Intent intent, int requestCode, @Nullable Bundle options) {
NotesApplication.updateLastInteraction();
super.startActivityForResult(intent, requestCode, options);
}
@Override
public void startActivityForResult(Intent intent, int requestCode) {
NotesApplication.updateLastInteraction();
super.startActivityForResult(intent, requestCode);
}
@Override
public void startActivity(Intent intent) {
NotesApplication.updateLastInteraction();
super.startActivity(intent);
}
@Override
public void startActivity(Intent intent, @Nullable Bundle options) {
NotesApplication.updateLastInteraction();
super.startActivity(intent, options);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == REQUEST_CODE_UNLOCK) {
if (resultCode == RESULT_OK) {
Log.v(TAG, "Successfully unlocked device");
NotesApplication.unlock();
} else {
Log.e(TAG, "Result code of unlocking was " + resultCode);
finish();
}
}
}
private void askToUnlock() {
if (NotesApplication.isLocked()) {
KeyguardManager keyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
if (keyguardManager != null) {
Intent i = keyguardManager.createConfirmDeviceCredentialIntent(getString(R.string.unlock_notes), null);
i.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivityForResult(i, REQUEST_CODE_UNLOCK);
} else {
Log.e(TAG, "Keyguard manager is null");
}
}
}
}
|