allow install history to be read from an ContentProvider

This allows a designated app to read the install history from F-Droid via a
ContentProvider.  The app is designated by the packageName defined in the
string install_history_reader_packageName.
This commit is contained in:
Hans-Christoph Steiner 2016-09-09 12:50:23 +02:00
parent c02125db01
commit f102ccff60
5 changed files with 36 additions and 3 deletions

View File

@ -109,6 +109,15 @@
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/apk_file_provider" />
</provider>
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="org.fdroid.fdroid.installer"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/install_history_file_provider" />
</provider>
<meta-data
android:name="android.app.default_searchable"

View File

@ -303,6 +303,17 @@ public class FDroidApp extends Application {
// TODO enable this based on a preference
InstallHistoryService.register(this);
String packageName = getString(R.string.install_history_reader_packageName);
String unset = getString(R.string.install_history_reader_packageName_UNSET);
if (!TextUtils.equals(packageName, unset)) {
int modeFlags = Intent.FLAG_GRANT_READ_URI_PERMISSION
| Intent.FLAG_GRANT_WRITE_URI_PERMISSION;
if (Build.VERSION.SDK_INT >= 19) {
modeFlags |= Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION;
}
grantUriPermission(packageName, InstallHistoryService.LOG_URI, modeFlags);
}
}
@TargetApi(18)

View File

@ -24,11 +24,11 @@ import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.Uri;
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;
@ -47,6 +47,8 @@ import java.util.List;
public class InstallHistoryService extends IntentService {
public static final String TAG = "InstallHistoryService";
public static final Uri LOG_URI = Uri.parse("content://org.fdroid.fdroid.installer/install_history/all");
private static BroadcastReceiver broadcastReceiver;
public static void register(Context context) {
@ -107,7 +109,9 @@ public class InstallHistoryService extends IntentService {
values.add(String.valueOf(versionCode));
values.add(intent.getAction());
File logFile = new File(getFilesDir(), getString(R.string.install_history_log_file));
File installHistoryDir = new File(getCacheDir(), "install_history");
installHistoryDir.mkdir();
File logFile = new File(installHistoryDir, "all");
FileWriter fw = null;
PrintWriter out = null;
try {

View File

@ -15,7 +15,10 @@
<string name="app_details_subject">%1$s on F-Droid</string>
<string name="install_history_log_file">all</string>
<!-- The unset value is set to a string that is impossible to be a valid Java package name. This
prevents abuse by creating malware with the same packageName as the unset string. -->
<string name="install_history_reader_packageName_UNSET">1-THIS MEANS NO APP IS GRANTED ACCESS!</string>
<string name="install_history_reader_packageName">@string/install_history_reader_packageName_UNSET</string>
<string-array name="updateIntervalValues">
<item>0</item>

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<paths>
<cache-path
name="install_history"
path="install_history" />
</paths>