blob: b049f76278373e12e4b289a340e8eab363c18925 (
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
|
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.gecko;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.os.Process;
import android.util.Log;
public class Restarter extends Service {
private static final String LOGTAG = "GeckoRestarter";
private void doRestart(Intent intent) {
final int oldProc = intent.getIntExtra("pid", -1);
if (oldProc < 0) {
return;
}
Process.killProcess(oldProc);
Log.d(LOGTAG, "Killed " + oldProc);
try {
Thread.sleep(100);
} catch (final InterruptedException e) {
}
final Intent restartIntent = (Intent)intent.getParcelableExtra(Intent.EXTRA_INTENT);
restartIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
.putExtra("didRestart", true)
.setClassName(getApplicationContext(),
AppConstants.MOZ_ANDROID_BROWSER_INTENT_CLASS);
startActivity(restartIntent);
Log.d(LOGTAG, "Launched " + restartIntent);
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
doRestart(intent);
stopSelf(startId);
return Service.START_NOT_STICKY;
}
@Override
public IBinder onBind(Intent intent) {
return null;
}
}
|