restructering services

This commit is contained in:
Dominik 2012-04-25 18:59:51 +02:00
parent 26a9a9e423
commit b63fe462a4
10 changed files with 59 additions and 37 deletions

View File

@ -223,23 +223,24 @@
android:name="org.thialfihar.android.apg.ui.HelpActivity"
android:label="@string/title_help" />
<service android:name=".Service" />
<service android:name=".service.PassphraseCacheService" />
<service android:name=".service.ApgService" />
<!-- <service -->
<!-- android:name=".ApgService2" -->
<!-- android:enabled="true" -->
<!-- android:exported="true" -->
<!-- android:permission="org.thialfihar.android.apg.permission.READ_KEY_DETAILS" -->
<!-- android:process=":remote" > -->
<!-- <intent-filter> -->
<!-- <action android:name="org.thialfihar.android.apg.IApgService" /> -->
<!-- </intent-filter> -->
<!-- <meta-data -->
<!-- android:name="api_version" -->
<!-- android:value="2" /> -->
<!-- </service> -->
<!-- TODO: need to be moved into new service model -->
<service
android:name=".service.ApgService2"
android:enabled="true"
android:exported="true"
android:permission="org.thialfihar.android.apg.permission.READ_KEY_DETAILS"
android:process=":remote" >
<intent-filter>
<action android:name="org.thialfihar.android.apg.service.IApgService2" />
</intent-filter>
<meta-data
android:name="api_version"
android:value="2" />
</service>
<provider
android:name=".provider.DataProvider"

View File

@ -14,7 +14,7 @@
package org.thialfihar.android.apg.provider;
import org.thialfihar.android.apg.ApgService2;
import org.thialfihar.android.apg.service.ApgService2;
import android.content.ContentUris;
import android.content.ContentValues;

View File

@ -14,8 +14,8 @@
package org.thialfihar.android.apg.provider;
import org.thialfihar.android.apg.ApgService2;
import org.thialfihar.android.apg.Constants;
import org.thialfihar.android.apg.service.ApgService2;
import android.content.ContentProvider;
import android.content.ContentValues;

View File

@ -0,0 +1,5 @@
package org.thialfihar.android.apg.service;
public class ApgRemoteService {
}

View File

@ -12,7 +12,7 @@
* limitations under the License.
*/
package org.thialfihar.android.apg;
package org.thialfihar.android.apg.service;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@ -25,8 +25,15 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import org.thialfihar.android.apg.IApgService;
import org.thialfihar.android.apg.Apg;
import org.thialfihar.android.apg.service.IApgService2;
import org.thialfihar.android.apg.Id;
import org.thialfihar.android.apg.InputData;
import org.thialfihar.android.apg.Preferences;
import org.thialfihar.android.apg.R;
import org.thialfihar.android.apg.service.IApgService2.Stub;
import org.thialfihar.android.apg.Id.database;
import org.thialfihar.android.apg.R.string;
import org.thialfihar.android.apg.provider.KeyRings;
import org.thialfihar.android.apg.provider.Keys;
import org.thialfihar.android.apg.provider.UserIds;
@ -40,7 +47,14 @@ import android.os.Bundle;
import android.os.IBinder;
import android.util.Log;
public class ApgService2 extends Service {
/**
* ATTENTION:
*
* This is the old ApgService used as remote service over aidl interface.
* It will be reworked!
*
*/
public class ApgService2 extends PassphraseCacheService {
private final static String TAG = "ApgService";
public static final boolean LOCAL_LOGV = true;
public static final boolean LOCAL_LOGD = true;
@ -536,7 +550,7 @@ public class ApgService2 extends Service {
return true;
}
private final IApgService.Stub mBinder = new IApgService.Stub() {
private final IApgService2.Stub mBinder = new IApgService2.Stub() {
public boolean getKeys(Bundle pArgs, Bundle pReturn) {

View File

@ -1,6 +1,6 @@
package org.thialfihar.android.apg;
package org.thialfihar.android.apg.service;
interface IApgService {
interface IApgService2 {
/* All functions fill the returnVals Bundle with the following keys:
*

View File

@ -12,14 +12,17 @@
* limitations under the License.
*/
package org.thialfihar.android.apg;
package org.thialfihar.android.apg.service;
import org.thialfihar.android.apg.Apg;
import android.app.Service;
import android.content.Intent;
import android.os.Binder;
import android.os.Handler;
import android.os.IBinder;
public class Service extends android.app.Service {
public class PassphraseCacheService extends Service {
private final IBinder mBinder = new LocalBinder();
public static final String EXTRA_TTL = "ttl";
@ -80,8 +83,8 @@ public class Service extends android.app.Service {
}
public class LocalBinder extends Binder {
Service getService() {
return Service.this;
PassphraseCacheService getService() {
return PassphraseCacheService.this;
}
}

View File

@ -28,7 +28,7 @@ import org.thialfihar.android.apg.Id;
import org.thialfihar.android.apg.PausableThread;
import org.thialfihar.android.apg.Preferences;
import org.thialfihar.android.apg.ProgressDialogUpdater;
import org.thialfihar.android.apg.Service;
import org.thialfihar.android.apg.service.PassphraseCacheService;
import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.app.SherlockActivity;
@ -92,8 +92,8 @@ public class BaseActivity extends SherlockFragmentActivity implements Runnable,
}
public static void startCacheService(Activity activity, Preferences preferences) {
Intent intent = new Intent(activity, Service.class);
intent.putExtra(Service.EXTRA_TTL, preferences.getPassPhraseCacheTtl());
Intent intent = new Intent(activity, PassphraseCacheService.class);
intent.putExtra(PassphraseCacheService.EXTRA_TTL, preferences.getPassPhraseCacheTtl());
activity.startService(intent);
}

View File

@ -84,7 +84,7 @@ public class EditKeyActivity extends SherlockFragmentActivity { // extends BaseA
Vector<PGPSecretKey> mKeys;
Vector<Integer> mKeysUsages;
// will be set to true to build layout later in handler
// will be set to false to build layout later in handler
private boolean mBuildLayout = true;
@Override
@ -300,7 +300,6 @@ public class EditKeyActivity extends SherlockFragmentActivity { // extends BaseA
} else {
mChangePassPhrase.setVisibility(View.VISIBLE);
}
}
});

View File

@ -16,7 +16,7 @@
package org.thialfihar.android.apg.util;
import org.thialfihar.android.apg.IApgService;
import org.thialfihar.android.apg.service.IApgService2;
import org.thialfihar.android.apg.util.ApgConInterface.OnCallFinishListener;
import android.content.ComponentName;
@ -97,13 +97,13 @@ public class ApgCon {
private final ArrayList<String> mWarningList = new ArrayList<String>();
/** Remote service for decrypting and encrypting data */
private IApgService mApgService = null;
private IApgService2 mApgService = null;
/** Set apgService accordingly to connection status */
private ServiceConnection mApgConnection = new ServiceConnection() {
public void onServiceConnected(ComponentName className, IBinder service) {
if( LOCAL_LOGD ) Log.d(TAG, "IApgService bound to apgService");
mApgService = IApgService.Stub.asInterface(service);
mApgService = IApgService2.Stub.asInterface(service);
}
public void onServiceDisconnected(ComponentName className) {
@ -231,7 +231,7 @@ public class ApgCon {
}
try {
mContext.bindService(new Intent(IApgService.class.getName()), mApgConnection, Context.BIND_AUTO_CREATE);
mContext.bindService(new Intent(IApgService2.class.getName()), mApgConnection, Context.BIND_AUTO_CREATE);
} catch (Exception e) {
Log.e(TAG, "could not bind APG service", e);
return false;
@ -370,7 +370,7 @@ public class ApgCon {
}
try {
Boolean success = (Boolean) IApgService.class.getMethod(function, Bundle.class, Bundle.class).invoke(mApgService, pArgs, pReturn);
Boolean success = (Boolean) IApgService2.class.getMethod(function, Bundle.class, Bundle.class).invoke(mApgService, pArgs, pReturn);
mErrorList.addAll(pReturn.getStringArrayList(ret.ERRORS.name()));
mWarningList.addAll(pReturn.getStringArrayList(ret.WARNINGS.name()));
return success;