blob: 1919343940aaa2e50b372e21e7312f0a6ea6cf5d (
plain)
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
|
/*
* mygram-droid: Android TV client for Foldergram.
* Copyright (C) 2026 Danilo M. <danix@danix.xyz>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published
* by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*/
package mygram.droid;
import android.app.Activity;
import android.app.Application;
import android.content.Intent;
import android.os.Bundle;
import java.net.CookieHandler;
import java.net.CookieManager;
import java.net.CookiePolicy;
public final class App extends Application implements Application.ActivityLifecycleCallbacks {
/** Until the PIN is entered; set again whenever the app leaves the screen. */
static boolean locked = true;
private int started;
@Override
public void onCreate() {
super.onCreate();
Prefs.init(this);
registerActivityLifecycleCallbacks(this);
// One cookie jar for the Foldergram session: Api, Glide and ExoPlayer
// all use HttpURLConnection, which consults the default handler.
CookieHandler.setDefault(new CookieManager(null, CookiePolicy.ACCEPT_ALL));
}
/** Before any screen draws, cover it with the PIN prompt if the app is locked. */
@Override
public void onActivityStarted(Activity a) {
started++;
if (locked && Prefs.hasPin() && !(a instanceof LockActivity))
a.startActivity(new Intent(a, LockActivity.class));
}
@Override
public void onActivityStopped(Activity a) {
if (--started == 0)
locked = true;
}
@Override
public void onActivityCreated(Activity a, Bundle state) {
}
@Override
public void onActivityResumed(Activity a) {
}
@Override
public void onActivityPaused(Activity a) {
}
@Override
public void onActivitySaveInstanceState(Activity a, Bundle state) {
}
@Override
public void onActivityDestroyed(Activity a) {
}
}
|