store install/uninstall history for later use
The install and uninstall history has lots of uses, including displaying to the user in the app itself, reporting to the Device Administrator to enable tracking of installs/uninstalls from the admin's app repo, etc. It can also be used as part of a "popularity contest" #396
This commit is contained in:
parent
cb4edbed44
commit
c02125db01
@ -468,6 +468,9 @@
|
||||
<service
|
||||
android:name=".installer.InstallManagerService"
|
||||
android:exported="false" />
|
||||
<service
|
||||
android:name=".installer.InstallHistoryService"
|
||||
android:exported="false" />
|
||||
<service
|
||||
android:name=".localrepo.CacheSwapAppsService"
|
||||
android:exported="false" />
|
||||
|
@ -56,6 +56,7 @@ import org.fdroid.fdroid.compat.PRNGFixes;
|
||||
import org.fdroid.fdroid.data.AppProvider;
|
||||
import org.fdroid.fdroid.data.InstalledAppProviderService;
|
||||
import org.fdroid.fdroid.data.Repo;
|
||||
import org.fdroid.fdroid.installer.InstallHistoryService;
|
||||
import org.fdroid.fdroid.net.IconDownloader;
|
||||
import org.fdroid.fdroid.net.WifiStateChangeService;
|
||||
|
||||
@ -299,6 +300,9 @@ public class FDroidApp extends Application {
|
||||
});
|
||||
|
||||
configureTor(Preferences.get().isTorEnabled());
|
||||
|
||||
// TODO enable this based on a preference
|
||||
InstallHistoryService.register(this);
|
||||
}
|
||||
|
||||
@TargetApi(18)
|
||||
|
@ -0,0 +1,124 @@
|
||||
/*
|
||||
* Copyright (C) 2016 Blue Jay Wireless
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 3
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
package org.fdroid.fdroid.installer;
|
||||
|
||||
import android.app.IntentService;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.os.Process;
|
||||
import android.support.v4.content.LocalBroadcastManager;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import org.fdroid.fdroid.R;
|
||||
import org.fdroid.fdroid.Utils;
|
||||
import org.fdroid.fdroid.data.Apk;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Saves all activity of installs and uninstalls to the database for later use, like
|
||||
* displaying in some kind of history viewer or reporting to a "popularity contest"
|
||||
* app tracker.
|
||||
*/
|
||||
public class InstallHistoryService extends IntentService {
|
||||
public static final String TAG = "InstallHistoryService";
|
||||
|
||||
private static BroadcastReceiver broadcastReceiver;
|
||||
|
||||
public static void register(Context context) {
|
||||
IntentFilter intentFilter = new IntentFilter();
|
||||
intentFilter.addDataScheme("http");
|
||||
intentFilter.addDataScheme("https");
|
||||
intentFilter.addDataScheme("package");
|
||||
intentFilter.addAction(Installer.ACTION_INSTALL_STARTED);
|
||||
intentFilter.addAction(Installer.ACTION_INSTALL_COMPLETE);
|
||||
intentFilter.addAction(Installer.ACTION_INSTALL_INTERRUPTED);
|
||||
intentFilter.addAction(Installer.ACTION_INSTALL_USER_INTERACTION);
|
||||
intentFilter.addAction(Installer.ACTION_UNINSTALL_STARTED);
|
||||
intentFilter.addAction(Installer.ACTION_UNINSTALL_COMPLETE);
|
||||
intentFilter.addAction(Installer.ACTION_UNINSTALL_INTERRUPTED);
|
||||
intentFilter.addAction(Installer.ACTION_UNINSTALL_USER_INTERACTION);
|
||||
|
||||
broadcastReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
queue(context, intent);
|
||||
}
|
||||
};
|
||||
LocalBroadcastManager localBroadcastManager = LocalBroadcastManager.getInstance(context);
|
||||
localBroadcastManager.registerReceiver(broadcastReceiver, intentFilter);
|
||||
}
|
||||
|
||||
public static void unregister(Context context) {
|
||||
LocalBroadcastManager localBroadcastManager = LocalBroadcastManager.getInstance(context);
|
||||
localBroadcastManager.unregisterReceiver(broadcastReceiver);
|
||||
}
|
||||
|
||||
public static void queue(Context context, Intent intent) {
|
||||
Utils.debugLog(TAG, "queue " + intent);
|
||||
intent.setClass(context, InstallHistoryService.class);
|
||||
context.startService(intent);
|
||||
}
|
||||
|
||||
public InstallHistoryService() {
|
||||
super("InstallHistoryService");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onHandleIntent(Intent intent) {
|
||||
Utils.debugLog(TAG, "onHandleIntent " + intent);
|
||||
if (intent == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Process.setThreadPriority(Process.THREAD_PRIORITY_LOWEST);
|
||||
long timestamp = System.currentTimeMillis();
|
||||
Apk apk = intent.getParcelableExtra(Installer.EXTRA_APK);
|
||||
String packageName = apk.packageName;
|
||||
int versionCode = apk.versionCode;
|
||||
|
||||
List<String> values = new ArrayList<>(4);
|
||||
values.add(String.valueOf(timestamp));
|
||||
values.add(packageName);
|
||||
values.add(String.valueOf(versionCode));
|
||||
values.add(intent.getAction());
|
||||
|
||||
File logFile = new File(getFilesDir(), getString(R.string.install_history_log_file));
|
||||
FileWriter fw = null;
|
||||
PrintWriter out = null;
|
||||
try {
|
||||
fw = new FileWriter(logFile, true);
|
||||
out = new PrintWriter(fw);
|
||||
out.println(TextUtils.join(",", values));
|
||||
} catch (IOException e) {
|
||||
Utils.debugLog(TAG, e.getMessage());
|
||||
} finally {
|
||||
Utils.closeQuietly(out);
|
||||
Utils.closeQuietly(fw);
|
||||
}
|
||||
}
|
||||
}
|
@ -7,7 +7,7 @@
|
||||
<string name="source_link">https://gitlab.com/fdroid/fdroidclient</string>
|
||||
<string name="team_email">team@f-droid.org</string>
|
||||
<string name="license_gplv3_later">GNU General Public License version\u00A03 or later</string>
|
||||
|
||||
|
||||
<string name="transition_app_item_icon">transition_app_item_icon</string>
|
||||
|
||||
<string name="https">https://</string>
|
||||
@ -15,6 +15,8 @@
|
||||
|
||||
<string name="app_details_subject">%1$s on F-Droid</string>
|
||||
|
||||
<string name="install_history_log_file">all</string>
|
||||
|
||||
<string-array name="updateIntervalValues">
|
||||
<item>0</item>
|
||||
<item>1</item>
|
||||
|
Loading…
x
Reference in New Issue
Block a user