aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/cyanogenmod/app
diff options
context:
space:
mode:
authorherriojr <jherriott@cyngn.com>2015-09-08 13:59:20 -0700
committerherriojr <jherriott@cyngn.com>2015-09-14 14:29:43 -0700
commite78ca4d6fecbd4a52ee02fe727810593e27950c2 (patch)
treed3b3010a746a9bf8c81804e9b441e9bf310d963c /src/java/cyanogenmod/app
parent35df988aa547c25d47975f3eaefd84cc61006647 (diff)
downloadvendor_cmsdk-e78ca4d6fecbd4a52ee02fe727810593e27950c2.zip
vendor_cmsdk-e78ca4d6fecbd4a52ee02fe727810593e27950c2.tar.gz
vendor_cmsdk-e78ca4d6fecbd4a52ee02fe727810593e27950c2.tar.bz2
Added Application Suggestions.
Added in custom Resolver to handle providing suggestions. Added in Service to handle providing suggestions to custom resolver. Added in ability to provider suggestions through a Proxy to another application which must be installed during compile time if one is to be used. This is a similar implementation to how the Location Services work. Change-Id: Id960260596b7bb6485caa1e1d07744e387a4c6e9
Diffstat (limited to 'src/java/cyanogenmod/app')
-rw-r--r--src/java/cyanogenmod/app/CMContextConstants.java5
-rw-r--r--src/java/cyanogenmod/app/suggest/AppSuggestManager.java140
-rw-r--r--src/java/cyanogenmod/app/suggest/ApplicationSuggestion.aidl22
-rw-r--r--src/java/cyanogenmod/app/suggest/ApplicationSuggestion.java118
-rw-r--r--src/java/cyanogenmod/app/suggest/IAppSuggestManager.aidl30
-rw-r--r--src/java/cyanogenmod/app/suggest/IAppSuggestProvider.aidl30
6 files changed, 345 insertions, 0 deletions
diff --git a/src/java/cyanogenmod/app/CMContextConstants.java b/src/java/cyanogenmod/app/CMContextConstants.java
index ab80b4f..b2278b1 100644
--- a/src/java/cyanogenmod/app/CMContextConstants.java
+++ b/src/java/cyanogenmod/app/CMContextConstants.java
@@ -85,4 +85,9 @@ public final class CMContextConstants {
* @hide
*/
public static final String CM_HARDWARE_SERVICE = "cmhardware";
+
+ /**
+ * @hide
+ */
+ public static final String CM_APP_SUGGEST_SERVICE = "cmappsuggest";
}
diff --git a/src/java/cyanogenmod/app/suggest/AppSuggestManager.java b/src/java/cyanogenmod/app/suggest/AppSuggestManager.java
new file mode 100644
index 0000000..7bc034c
--- /dev/null
+++ b/src/java/cyanogenmod/app/suggest/AppSuggestManager.java
@@ -0,0 +1,140 @@
+/**
+ * Copyright (c) 2015, The CyanogenMod Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package cyanogenmod.app.suggest;
+
+import android.content.Context;
+import android.content.Intent;
+import android.graphics.BitmapFactory;
+import android.graphics.drawable.BitmapDrawable;
+import android.graphics.drawable.Drawable;
+import android.os.IBinder;
+import android.os.RemoteException;
+import android.os.ServiceManager;
+import android.util.Log;
+
+import java.io.FileNotFoundException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+
+import cyanogenmod.app.CMContextConstants;
+import cyanogenmod.app.suggest.ApplicationSuggestion;
+
+/**
+ * Provides an interface to get information about suggested apps for an intent which may include
+ * applications not installed on the device. This is used by the CMResolver in order to provide
+ * suggestions when an intent is fired but no application exists for the given intent.
+ *
+ * @hide
+ */
+public class AppSuggestManager {
+ private static final String TAG = AppSuggestManager.class.getSimpleName();
+ private static final boolean DEBUG = true;
+
+ private static IAppSuggestManager sImpl;
+
+ private static AppSuggestManager sInstance;
+
+ private Context mContext;
+
+ /**
+ * Gets an instance of the AppSuggestManager.
+ *
+ * @param context
+ *
+ * @return An instance of the AppSuggestManager
+ */
+ public static synchronized AppSuggestManager getInstance(Context context) {
+ if (sInstance != null) {
+ return sInstance;
+ }
+
+ context = context.getApplicationContext() != null ? context.getApplicationContext() : context;
+
+ sInstance = new AppSuggestManager(context);
+
+ return sInstance;
+ }
+
+ private AppSuggestManager(Context context) {
+ mContext = context.getApplicationContext();
+ }
+
+ private static synchronized IAppSuggestManager getService() {
+ if (sImpl == null) {
+ IBinder b = ServiceManager.getService(CMContextConstants.CM_APP_SUGGEST_SERVICE);
+ if (b != null) {
+ sImpl = IAppSuggestManager.Stub.asInterface(b);
+ } else {
+ Log.e(TAG, "Unable to find implementation for app suggest service");
+ }
+ }
+
+ return sImpl;
+ }
+
+ /**
+ * Checks to see if an intent is handled by the App Suggestions Service. This should be
+ * implemented in such a way that it is safe to call inline on the UI Thread.
+ *
+ * @param intent The intent
+ * @return true if the App Suggestions Service has suggestions for this intent, false otherwise
+ */
+ public boolean handles(Intent intent) {
+ IAppSuggestManager mgr = getService();
+ if (mgr == null) return false;
+ try {
+ return mgr.handles(intent);
+ } catch (RemoteException e) {
+ return false;
+ }
+ }
+
+ /**
+ *
+ * Gets a list of the suggestions for the given intent.
+ *
+ * @param intent The intent
+ * @return A list of application suggestions or an empty list if none.
+ */
+ public List<ApplicationSuggestion> getSuggestions(Intent intent) {
+ IAppSuggestManager mgr = getService();
+ if (mgr == null) return new ArrayList<>(0);
+ try {
+ return mgr.getSuggestions(intent);
+ } catch (RemoteException e) {
+ return new ArrayList<>(0);
+ }
+ }
+
+ /**
+ * Loads the icon for the given suggestion.
+ *
+ * @param suggestion The suggestion to load the icon for
+ *
+ * @return A {@link Drawable} or null if one cannot be found
+ */
+ public Drawable loadIcon(ApplicationSuggestion suggestion) {
+ try {
+ InputStream is = mContext.getContentResolver()
+ .openInputStream(suggestion.getThumbailUri());
+ return Drawable.createFromStream(is, null);
+ } catch (FileNotFoundException e) {
+ return null;
+ }
+ }
+}
diff --git a/src/java/cyanogenmod/app/suggest/ApplicationSuggestion.aidl b/src/java/cyanogenmod/app/suggest/ApplicationSuggestion.aidl
new file mode 100644
index 0000000..7ab8584
--- /dev/null
+++ b/src/java/cyanogenmod/app/suggest/ApplicationSuggestion.aidl
@@ -0,0 +1,22 @@
+/**
+ * Copyright (c) 2015, The CyanogenMod Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package cyanogenmod.app.suggest;
+
+/**
+ * @hide
+ */
+parcelable ApplicationSuggestion;
diff --git a/src/java/cyanogenmod/app/suggest/ApplicationSuggestion.java b/src/java/cyanogenmod/app/suggest/ApplicationSuggestion.java
new file mode 100644
index 0000000..c10afe3
--- /dev/null
+++ b/src/java/cyanogenmod/app/suggest/ApplicationSuggestion.java
@@ -0,0 +1,118 @@
+/**
+ * Copyright (c) 2015, The CyanogenMod Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package cyanogenmod.app.suggest;
+
+import android.annotation.NonNull;
+import android.net.Uri;
+import android.os.Parcel;
+import android.os.Parcelable;
+import cyanogenmod.os.Build;
+
+/**
+ * @hide
+ */
+public class ApplicationSuggestion implements Parcelable {
+
+ public static final Creator<ApplicationSuggestion> CREATOR =
+ new Creator<ApplicationSuggestion>() {
+ public ApplicationSuggestion createFromParcel(Parcel in) {
+ return new ApplicationSuggestion(in);
+ }
+
+ public ApplicationSuggestion[] newArray(int size) {
+ return new ApplicationSuggestion[size];
+ }
+ };
+
+ private String mName;
+
+ private String mPackage;
+
+ private Uri mDownloadUri;
+
+ private Uri mThumbnailUri;
+
+ public ApplicationSuggestion(@NonNull String name, @NonNull String pkg,
+ @NonNull Uri downloadUri, @NonNull Uri thumbnailUri) {
+ mName = name;
+ mPackage = pkg;
+ mDownloadUri = downloadUri;
+ mThumbnailUri = thumbnailUri;
+ }
+
+ private ApplicationSuggestion(Parcel in) {
+ // Read parcelable version, make sure to define explicit changes
+ // within {@link Build.PARCELABLE_VERSION);
+ int parcelableVersion = in.readInt();
+ int parcelableSize = in.readInt();
+ int startPosition = in.dataPosition();
+
+ if (parcelableVersion >= Build.CM_VERSION_CODES.APRICOT) {
+ mName = in.readString();
+ mPackage = in.readString();
+ mDownloadUri = in.readParcelable(Uri.class.getClassLoader());
+ mThumbnailUri = in.readParcelable(Uri.class.getClassLoader());
+ }
+
+ in.setDataPosition(startPosition + parcelableSize);
+ }
+
+ @Override
+ public int describeContents() {
+ return 0;
+ }
+
+ @Override
+ public void writeToParcel(Parcel out, int flags) {
+ // Write parcelable version, make sure to define explicit changes
+ // within {@link Build.PARCELABLE_VERSION);
+ out.writeInt(Build.PARCELABLE_VERSION);
+
+ // Inject a placeholder that will store the parcel size from this point on
+ // (not including the size itself).
+ int sizePosition = out.dataPosition();
+ out.writeInt(0);
+ int startPosition = out.dataPosition();
+
+ out.writeString(mName);
+ out.writeString(mPackage);
+ out.writeParcelable(mDownloadUri, flags);
+ out.writeParcelable(mThumbnailUri, flags);
+
+ // Go back and write size
+ int parcelableSize = out.dataPosition() - startPosition;
+ out.setDataPosition(sizePosition);
+ out.writeInt(parcelableSize);
+ out.setDataPosition(startPosition + parcelableSize);
+ }
+
+ public String getName() {
+ return mName;
+ }
+
+ public String getPackageName() {
+ return mPackage;
+ }
+
+ public Uri getDownloadUri() {
+ return mDownloadUri;
+ }
+
+ public Uri getThumbailUri() {
+ return mThumbnailUri;
+ }
+}
diff --git a/src/java/cyanogenmod/app/suggest/IAppSuggestManager.aidl b/src/java/cyanogenmod/app/suggest/IAppSuggestManager.aidl
new file mode 100644
index 0000000..68ab87f
--- /dev/null
+++ b/src/java/cyanogenmod/app/suggest/IAppSuggestManager.aidl
@@ -0,0 +1,30 @@
+/**
+ * Copyright (c) 2015, The CyanogenMod Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package cyanogenmod.app.suggest;
+
+import android.content.Intent;
+
+import cyanogenmod.app.suggest.ApplicationSuggestion;
+
+/**
+ * @hide
+ */
+interface IAppSuggestManager {
+ boolean handles(in Intent intent);
+
+ List<ApplicationSuggestion> getSuggestions(in Intent intent);
+} \ No newline at end of file
diff --git a/src/java/cyanogenmod/app/suggest/IAppSuggestProvider.aidl b/src/java/cyanogenmod/app/suggest/IAppSuggestProvider.aidl
new file mode 100644
index 0000000..759880d
--- /dev/null
+++ b/src/java/cyanogenmod/app/suggest/IAppSuggestProvider.aidl
@@ -0,0 +1,30 @@
+/**
+ * Copyright (c) 2015, The CyanogenMod Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package cyanogenmod.app.suggest;
+
+import android.content.Intent;
+
+import cyanogenmod.app.suggest.ApplicationSuggestion;
+
+/**
+ * @hide
+ */
+interface IAppSuggestProvider {
+ boolean handles(in Intent intent);
+
+ List<ApplicationSuggestion> getSuggestions(in Intent intent);
+} \ No newline at end of file