101 lines
3.0 KiB
Java
101 lines
3.0 KiB
Java
package com.google.zxing.client.android;
|
|
|
|
import android.app.Activity;
|
|
import android.content.BroadcastReceiver;
|
|
import android.content.Context;
|
|
import android.content.Intent;
|
|
import android.content.IntentFilter;
|
|
import android.os.AsyncTask;
|
|
import android.util.Log;
|
|
import java.util.concurrent.RejectedExecutionException;
|
|
|
|
/* loaded from: classes.dex */
|
|
public final class InactivityTimer {
|
|
private static final String e = "InactivityTimer";
|
|
private final Activity a;
|
|
private final BroadcastReceiver b = new PowerStatusReceiver();
|
|
private boolean c = false;
|
|
private AsyncTask<Object, Object, Object> d;
|
|
|
|
private final class InactivityAsyncTask extends AsyncTask<Object, Object, Object> {
|
|
private InactivityAsyncTask() {
|
|
}
|
|
|
|
@Override // android.os.AsyncTask
|
|
protected Object doInBackground(Object... objArr) {
|
|
try {
|
|
Thread.sleep(300000L);
|
|
Log.i(InactivityTimer.e, "Finishing activity due to inactivity");
|
|
InactivityTimer.this.a.finish();
|
|
return null;
|
|
} catch (InterruptedException unused) {
|
|
return null;
|
|
}
|
|
}
|
|
}
|
|
|
|
private final class PowerStatusReceiver extends BroadcastReceiver {
|
|
private PowerStatusReceiver() {
|
|
}
|
|
|
|
@Override // android.content.BroadcastReceiver
|
|
public void onReceive(Context context, Intent intent) {
|
|
if ("android.intent.action.BATTERY_CHANGED".equals(intent.getAction())) {
|
|
if (intent.getIntExtra("plugged", -1) <= 0) {
|
|
InactivityTimer.this.a();
|
|
} else {
|
|
InactivityTimer.this.f();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public InactivityTimer(Activity activity) {
|
|
this.a = activity;
|
|
a();
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
public synchronized void f() {
|
|
AsyncTask<Object, Object, Object> asyncTask = this.d;
|
|
if (asyncTask != null) {
|
|
asyncTask.cancel(true);
|
|
this.d = null;
|
|
}
|
|
}
|
|
|
|
public synchronized void c() {
|
|
if (this.c) {
|
|
Log.w(e, "PowerStatusReceiver was already registered?");
|
|
} else {
|
|
this.a.registerReceiver(this.b, new IntentFilter("android.intent.action.BATTERY_CHANGED"));
|
|
this.c = true;
|
|
}
|
|
a();
|
|
}
|
|
|
|
public void d() {
|
|
f();
|
|
}
|
|
|
|
public synchronized void a() {
|
|
f();
|
|
this.d = new InactivityAsyncTask();
|
|
try {
|
|
this.d.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, new Object[0]);
|
|
} catch (RejectedExecutionException unused) {
|
|
Log.w(e, "Couldn't schedule inactivity task; ignoring");
|
|
}
|
|
}
|
|
|
|
public synchronized void b() {
|
|
f();
|
|
if (this.c) {
|
|
this.a.unregisterReceiver(this.b);
|
|
this.c = false;
|
|
} else {
|
|
Log.w(e, "PowerStatusReceiver was never registered?");
|
|
}
|
|
}
|
|
}
|