diff options
author | Sunny Goyal <sunnygoyal@google.com> | 2019-03-22 14:13:36 -0700 |
---|---|---|
committer | Sunny Goyal <sunnygoyal@google.com> | 2019-04-10 12:06:17 -0700 |
commit | c0f03d96656a3c70a26d3ec97e9e782fbdbe64b9 (patch) | |
tree | 8696c1cb8b375fc1efa50e8ae4fed2a5c51d1010 /tests/src/com/android/launcher3/testcomponent/TestCommandReceiver.java | |
parent | e09e1f2253a9f20f1c91532956053a11b43ad355 (diff) | |
download | android_packages_apps_Trebuchet-c0f03d96656a3c70a26d3ec97e9e782fbdbe64b9.tar.gz android_packages_apps_Trebuchet-c0f03d96656a3c70a26d3ec97e9e782fbdbe64b9.tar.bz2 android_packages_apps_Trebuchet-c0f03d96656a3c70a26d3ec97e9e782fbdbe64b9.zip |
Adding support for loading the default layout from a content provider
The autority of the provider should be set in secure settings:
launcher3.layout.provider
Bug: 127987071
Change-Id: Iccf2960aa6c0a5a8ff9621b13d8963d9daecb993
Diffstat (limited to 'tests/src/com/android/launcher3/testcomponent/TestCommandReceiver.java')
-rw-r--r-- | tests/src/com/android/launcher3/testcomponent/TestCommandReceiver.java | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/tests/src/com/android/launcher3/testcomponent/TestCommandReceiver.java b/tests/src/com/android/launcher3/testcomponent/TestCommandReceiver.java index 0edb3d61b..fa23b8d5b 100644 --- a/tests/src/com/android/launcher3/testcomponent/TestCommandReceiver.java +++ b/tests/src/com/android/launcher3/testcomponent/TestCommandReceiver.java @@ -18,6 +18,7 @@ package com.android.launcher3.testcomponent; import static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_DISABLED; import static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_ENABLED; import static android.content.pm.PackageManager.DONT_KILL_APP; +import static android.os.ParcelFileDescriptor.MODE_READ_WRITE; import android.app.Activity; import android.app.ActivityManager; @@ -28,6 +29,13 @@ import android.content.ContentValues; import android.database.Cursor; import android.net.Uri; import android.os.Bundle; +import android.os.ParcelFileDescriptor; +import android.util.Base64; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; import androidx.test.InstrumentationRegistry; @@ -104,4 +112,19 @@ public class TestCommandReceiver extends ContentProvider { Uri uri = Uri.parse("content://" + inst.getContext().getPackageName() + ".commands"); return inst.getTargetContext().getContentResolver().call(uri, command, arg, null); } + + @Override + public ParcelFileDescriptor openFile(Uri uri, String mode) throws FileNotFoundException { + String path = Base64.encodeToString(uri.getPath().getBytes(), + Base64.NO_CLOSE | Base64.NO_PADDING | Base64.NO_WRAP); + File file = new File(getContext().getCacheDir(), path); + if (!file.exists()) { + // Create an empty file so that we can pass its descriptor + try { + file.createNewFile(); + } catch (IOException e) { } + } + + return ParcelFileDescriptor.open(file, MODE_READ_WRITE); + } } |