Implement more People APIs and add some stubs

This commit is contained in:
mar-v-in 2015-03-25 23:12:03 +01:00
parent 3274300cdf
commit cdc5fc0bde
9 changed files with 246 additions and 21 deletions

2
extern/GmsApi vendored

@ -1 +1 @@
Subproject commit c0c4a78eab3064cdd7545cb7fcdddfe93ca1674d
Subproject commit c43facae3dba6fcf4139c6a36e3a6f364d6db057

View File

@ -148,6 +148,10 @@
android:name="org.microg.gms.gcm.mcs.McsService"
android:exported="true" />
<service
android:name="com.google.android.gms.gcm.http.GoogleHttpService"
android:exported="true" />
<!-- DroidGuard -->
<service
@ -228,10 +232,10 @@
android:excludeFromRecents="true" />
<service
android:name=".auth.GetToken"
android:name="com.google.android.gms.auth.GetToken"
android:exported="true" />
<activity
android:name=".auth.TokenActivity"
android:name="com.google.android.gms.auth.TokenActivity"
android:exported="true" />
<!-- Other -->
@ -268,5 +272,13 @@
<action android:name="com.google.android.gms.analytics.service.START" />
</intent-filter>
</service>
<service
android:name="org.microg.gms.playlog.PlayLogService"
android:exported="true">
<intent-filter>
<action android:name="com.google.android.gms.playlog.service.START" />
</intent-filter>
</service>
</application>
</manifest>

View File

@ -0,0 +1,37 @@
/*
* Copyright 2013-2015 µg Project Team
*
* 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 com.google.android.gms.gcm.http;
import android.app.Service;
import android.content.Intent;
import android.os.Bundle;
import android.os.IBinder;
import android.os.RemoteException;
import com.google.android.gms.http.IGoogleHttpService;
public class GoogleHttpService extends Service {
@Override
public IBinder onBind(Intent intent) {
return new IGoogleHttpService.Stub() {
@Override
public Bundle checkUrl(String url) throws RemoteException {
return null; // allow
}
}.asBinder();
}
}

View File

@ -105,7 +105,7 @@ public class AskPermissionActivity extends AccountAuthenticatorActivity {
}
CharSequence appLabel = packageManager.getApplicationLabel(applicationInfo);
Drawable appIcon = packageManager.getApplicationIcon(applicationInfo);
Bitmap profileIcon = PeopleManager.getUserPicture(this, account, false);
Bitmap profileIcon = PeopleManager.getOwnerAvatarBitmap(this, account.name, false);
// receive profile icon
if (profileIcon != null) {
@ -114,7 +114,7 @@ public class AskPermissionActivity extends AccountAuthenticatorActivity {
new Thread(new Runnable() {
@Override
public void run() {
final Bitmap profileIcon = PeopleManager.getUserPicture(AskPermissionActivity.this, account, true);
final Bitmap profileIcon = PeopleManager.getOwnerAvatarBitmap(AskPermissionActivity.this, account.name, true);
runOnUiThread(new Runnable() {
@Override
public void run() {

View File

@ -23,7 +23,7 @@ import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
public class DatabaseHelper extends SQLiteOpenHelper {
private static final int DB_VERSION = 1;
private static final int DB_VERSION = 2;
private static final String DB_NAME = "pluscontacts.db";
private static final String CREATE_OWNERS = "CREATE TABLE owners (" +
"_id INTEGER PRIMARY KEY AUTOINCREMENT," +
@ -47,7 +47,21 @@ public class DatabaseHelper extends SQLiteOpenHelper {
"sync_circles_to_contacts INTEGER NOT NULL DEFAULT 0," + // 0
"sync_evergreen_to_contacts INTEGER NOT NULL DEFAULT 0," + // 0
"last_full_people_sync_time INTEGER NOT NULL DEFAULT 0);"; // timestamp
private static final String CREATE_CIRCLES = "CREATE TABLE circles (" +
"_id INTEGER PRIMARY KEY AUTOINCREMENT," +
"owner_id INTEGER NOT NULL," +
"circle_id TEXT NOT NULL," +
"name TEXT,sort_key TEXT," +
"type INTEGER NOT NULL," +
"for_sharing INTEGER NOT NULL DEFAULT 0," +
"people_count INTEGER NOT NULL DEFAULT -1," +
"client_policies INTEGER NOT NULL DEFAULT 0," +
"etag TEXT,last_modified INTEGER NOT NULL DEFAULT 0," +
"sync_to_contacts INTEGER NOT NULL DEFAULT 0," +
"UNIQUE (owner_id,circle_id)," +
"FOREIGN KEY (owner_id) REFERENCES owners(_id) ON DELETE CASCADE);";
public static final String OWNERS_TABLE = "owners";
public static final String CIRCLES_TABLE = "circles";
public DatabaseHelper(Context context) {
@ -61,7 +75,7 @@ public class DatabaseHelper extends SQLiteOpenHelper {
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
if (oldVersion < 2) db.execSQL(CREATE_CIRCLES);
}
@Override
@ -80,4 +94,10 @@ public class DatabaseHelper extends SQLiteOpenHelper {
public Cursor getOwner(String accountName) {
return getReadableDatabase().query(OWNERS_TABLE, null, "account_name=?", new String[]{accountName}, null, null, null);
}
public Cursor getCircles(int ownerId, String circleId, int type) {
return getReadableDatabase().query(CIRCLES_TABLE, null,
"owner_id=?1 AND (circle_id = ?2 OR ?2 = '') AND (type = ?3 OR ?3 = -999 OR (?3 = -998 AND type = -1))",
new String[]{Integer.toString(ownerId), circleId != null ? circleId : "", Integer.toString(type)}, null, null, null);
}
}

View File

@ -33,6 +33,8 @@ import org.microg.gms.auth.AuthResponse;
import org.microg.gms.common.Constants;
import org.microg.gms.common.Utils;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URL;
import java.net.URLConnection;
@ -43,9 +45,9 @@ public class PeopleManager {
public static final String USERINFO_URL = "https://www.googleapis.com/oauth2/v1/userinfo";
public static final String REGEX_SEARCH_USER_PHOTO = "https?\\:\\/\\/lh([0-9]*)\\.googleusercontent\\.com/";
public static Bitmap getUserPicture(Context context, Account account, boolean network) {
public static File getOwnerAvaterFile(Context context, String accountName, boolean network) {
DatabaseHelper databaseHelper = new DatabaseHelper(context);
Cursor cursor = databaseHelper.getOwner(account.name);
Cursor cursor = databaseHelper.getOwner(accountName);
String url = null;
if (cursor.moveToNext()) {
int idx = cursor.getColumnIndex("avatar");
@ -54,20 +56,32 @@ public class PeopleManager {
cursor.close();
databaseHelper.close();
if (url == null) return null;
// TODO: load from cache
String urlLastPart = url.substring(3);
File file = new File(context.getCacheDir(), urlLastPart);
if (!file.getParentFile().mkdirs() && file.exists()) {
return file;
}
if (!network) return null;
url = "https://lh" + url.toCharArray()[1] + ".googleusercontent.com" + url.substring(2);
url = "https://lh" + url.toCharArray()[1] + ".googleusercontent.com/" + urlLastPart;
try {
URLConnection conn = new URL(url).openConnection();
conn.setDoInput(true);
byte[] bytes = Utils.readStreamToEnd(conn.getInputStream());
// TODO: store to cache
Bitmap bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
return bitmap;
FileOutputStream outputStream = new FileOutputStream(file);
outputStream.write(bytes);
outputStream.close();
return file;
} catch (Exception e) {
Log.w(TAG, e);
return null;
}
}
public static Bitmap getOwnerAvatarBitmap(Context context, String accountName, boolean network) {
File avaterFile = getOwnerAvaterFile(context, accountName, network);
if (avaterFile == null) return null;
return BitmapFactory.decodeFile(avaterFile.getPath());
}
public static void loadUserInfo(Context context, Account account) {

View File

@ -19,8 +19,10 @@ package org.microg.gms.people;
import android.accounts.Account;
import android.accounts.AccountManager;
import android.content.Context;
import android.database.Cursor;
import android.os.Bundle;
import android.os.Parcel;
import android.os.ParcelFileDescriptor;
import android.os.RemoteException;
import android.util.Log;
@ -30,6 +32,8 @@ import com.google.android.gms.common.internal.ICancelToken;
import com.google.android.gms.people.internal.IPeopleCallbacks;
import com.google.android.gms.people.internal.IPeopleService;
import java.io.File;
public class PeopleServiceImpl extends IPeopleService.Stub {
private static final String TAG = "GmsPeopleSvcImpl";
private Context context;
@ -42,18 +46,18 @@ public class PeopleServiceImpl extends IPeopleService.Stub {
public void loadOwners(final IPeopleCallbacks callbacks, boolean var2, boolean var3, final String accountName, String var5, int sortOrder) {
Log.d(TAG, "loadOwners: " + var2 + ", " + var3 + ", " + accountName + ", " + var5 + ", " + sortOrder);
AccountManager accountManager = AccountManager.get(context);
Bundle result = new Bundle();
Bundle extras = new Bundle();
String accountType = context.getString(R.string.google_account_type);
for (Account account : accountManager.getAccountsByType(accountType)) {
if (accountName == null || account.name.equals(accountName)) {
result.putParcelable(account.name, null);
extras.putParcelable(account.name, null);
}
}
try {
DatabaseHelper databaseHelper = new DatabaseHelper(context);
DataHolder dataHolder = DataHolder.fromCursor(databaseHelper.getOwners(), 0, result);
DataHolder dataHolder = DataHolder.fromCursor(databaseHelper.getOwners(), 0, extras);
Log.d(TAG, "loadOwners[result]: " + dataHolder);
callbacks.onDataHolder(0, result, dataHolder);
callbacks.onDataHolder(0, extras, dataHolder);
databaseHelper.close();
} catch (Exception e) {
Log.w(TAG, e);
@ -61,17 +65,75 @@ public class PeopleServiceImpl extends IPeopleService.Stub {
}
@Override
public Bundle registerDataChangedListener(IPeopleCallbacks callbacks, boolean register, String var3, String var4, int scopes) {
public void loadPeopleForAggregation(IPeopleCallbacks callbacks, String account, String var3, String filter, int var5, boolean var6, int var7, int var8, String var9, boolean var10, int var11, int var12) throws RemoteException {
Log.d(TAG, "loadPeopleForAggregation: " + account + ", " + var3 + ", " + filter + ", " + var5 + ", " + var6 + ", " + var7 + ", " + var8 + ", " + var9 + ", " + var10 + ", " + var11 + ", " + var12);
callbacks.onDataHolder(0, new Bundle(), null);
}
@Override
public Bundle registerDataChangedListener(IPeopleCallbacks callbacks, boolean register, String var3, String var4, int scopes) throws RemoteException {
Log.d(TAG, "registerDataChangedListener: " + register + ", " + var3 + ", " + var4 + ", " + scopes);
callbacks.onDataHolder(0, new Bundle(), null);
return null;
}
@Override
public ICancelToken loadOwnerAvatar(IPeopleCallbacks callbacks, String account, String pageId, int size, int flags) {
Log.d(TAG, "loadOwnerAvatar: " + account + ", " + pageId + ", " + size + ", " + flags);
public void loadCircles(IPeopleCallbacks callbacks, String account, String pageGaiaId, String circleId, int type, String var6, boolean var7) throws RemoteException {
Log.d(TAG, "loadCircles: " + account + ", " + pageGaiaId + ", " + circleId + ", " + type + ", " + var6 + ", " + var7);
try {
DatabaseHelper databaseHelper = new DatabaseHelper(context);
Cursor owner = databaseHelper.getOwner(account);
int ownerId = -1;
if (owner.moveToNext()) {
ownerId = owner.getInt(0);
}
owner.close();
Bundle extras = new Bundle();
DataHolder dataHolder = DataHolder.fromCursor(databaseHelper.getCircles(ownerId, circleId, type), 0, extras);
callbacks.onDataHolder(0, new Bundle(), dataHolder);
databaseHelper.close();
} catch (Exception e) {
Log.w(TAG, e);
}
}
@Override
public Bundle requestSync(String account, String var2, long var3, boolean var5, boolean var6) throws RemoteException {
Log.d(TAG, "requestSync: " + account + ", " + var2 + ", " + var3 + ", " + var5 + ", " + var6);
return null;
}
@Override
public ICancelToken loadOwnerAvatar(final IPeopleCallbacks callbacks, final String account, String pageId, int size, int flags) {
Log.d(TAG, "loadOwnerAvatar: " + account + ", " + pageId + ", " + size + ", " + flags);
final Thread thread = new Thread(new Runnable() {
@Override
public void run() {
Bundle extras = new Bundle();
extras.putBoolean("rewindable", false);
extras.putInt("width", 0);
extras.putInt("height", 0);
File avaterFile = PeopleManager.getOwnerAvaterFile(context, account, true);
try {
ParcelFileDescriptor fileDescriptor = null;
if (avaterFile != null) {
fileDescriptor = ParcelFileDescriptor.open(avaterFile, ParcelFileDescriptor.MODE_READ_ONLY);
}
callbacks.onParcelFileDescriptor(0, extras, fileDescriptor, extras);
} catch (Exception e) {
Log.w(TAG, e);
}
}
});
thread.start();
return new ICancelToken.Stub() {
@Override
public void cancel() throws RemoteException {
thread.interrupt();
}
};
}
@Override
public boolean onTransact(int code, Parcel data, Parcel reply, int flags) throws RemoteException {
if (super.onTransact(code, data, reply, flags)) return true;

View File

@ -0,0 +1,46 @@
/*
* Copyright 2013-2015 µg Project Team
*
* 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 org.microg.gms.playlog;
import android.app.Service;
import android.content.Intent;
import android.os.Bundle;
import android.os.IBinder;
import android.os.RemoteException;
import android.util.Log;
import com.google.android.gms.common.internal.IGmsCallbacks;
import org.microg.gms.AbstractGmsServiceBroker;
public class PlayLogService extends Service {
private static final String TAG = "GmsPlayLogSvc";
private PlayLogServiceImpl playLogService = new PlayLogServiceImpl();
private AbstractGmsServiceBroker broker = new AbstractGmsServiceBroker() {
@Override
public void getPlayLogService(IGmsCallbacks callback, int versionCode, String packageName, Bundle params) throws RemoteException {
Log.d(TAG, "bound by: " + packageName);
callback.onPostInitComplete(0, playLogService.asBinder(), null);
}
};
@Override
public IBinder onBind(Intent intent) {
return broker.asBinder();
}
}

View File

@ -0,0 +1,34 @@
/*
* Copyright 2013-2015 µg Project Team
*
* 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 org.microg.gms.playlog;
import android.os.Parcel;
import android.os.RemoteException;
import android.util.Log;
import com.google.android.gms.playlog.internal.IPlayLogService;
public class PlayLogServiceImpl extends IPlayLogService.Stub {
private static final String TAG = "GmsPlayLogSvcImpl";
@Override
public boolean onTransact(int code, Parcel data, Parcel reply, int flags) throws RemoteException {
if (super.onTransact(code, data, reply, flags)) return true;
Log.d(TAG, "onTransact [unknown]: " + code + ", " + data + ", " + flags);
return false;
}
}