• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

development


Commit MetaInfo

Révision40e665a015c67a8dd21838894a1634a3e101b760 (tree)
l'heure2010-02-11 04:18:23
AuteurJames Yum <jyum@goog...>
CommiterJames Yum

Message de Log

cleanup

deleted: licensing/ILicenseResultListener.aidl
deleted: licensing/ILicensingService.aidl
deleted: licensing/LicenseChecker.java
deleted: licensing/LicenseCheckerCallback.java
deleted: licensing/LicenseValidator.java
deleted: licensing/Policy.java
deleted: licensing/ResponseData.java
deleted: licensing/StrictPolicy.java

Change Summary

  • delete: samples/MarketLicensing/src/com/android/vending/licensing/ILicenseResultListener.aidl
  • delete: samples/MarketLicensing/src/com/android/vending/licensing/ILicensingService.aidl
  • delete: samples/MarketLicensing/src/com/android/vending/licensing/LicenseChecker.java
  • delete: samples/MarketLicensing/src/com/android/vending/licensing/LicenseCheckerCallback.java
  • delete: samples/MarketLicensing/src/com/android/vending/licensing/LicenseValidator.java
  • delete: samples/MarketLicensing/src/com/android/vending/licensing/Policy.java
  • delete: samples/MarketLicensing/src/com/android/vending/licensing/ResponseData.java
  • delete: samples/MarketLicensing/src/com/android/vending/licensing/StrictPolicy.java

Modification

--- a/samples/MarketLicensing/src/com/android/vending/licensing/ILicenseResultListener.aidl
+++ /dev/null
@@ -1,21 +0,0 @@
1-/*
2- * Copyright (C) 2010 The Android Open Source Project
3- *
4- * Licensed under the Apache License, Version 2.0 (the "License");
5- * you may not use this file except in compliance with the License.
6- * You may obtain a copy of the License at
7- *
8- * http://www.apache.org/licenses/LICENSE-2.0
9- *
10- * Unless required by applicable law or agreed to in writing, software
11- * distributed under the License is distributed on an "AS IS" BASIS,
12- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13- * See the License for the specific language governing permissions and
14- * limitations under the License.
15- */
16-
17-package com.android.vending.licensing;
18-
19-oneway interface ILicenseResultListener {
20- void verifyLicense(int responseCode, String signedData, String signature);
21-}
--- a/samples/MarketLicensing/src/com/android/vending/licensing/ILicensingService.aidl
+++ /dev/null
@@ -1,23 +0,0 @@
1-/*
2- * Copyright (C) 2010 The Android Open Source Project
3- *
4- * Licensed under the Apache License, Version 2.0 (the "License");
5- * you may not use this file except in compliance with the License.
6- * You may obtain a copy of the License at
7- *
8- * http://www.apache.org/licenses/LICENSE-2.0
9- *
10- * Unless required by applicable law or agreed to in writing, software
11- * distributed under the License is distributed on an "AS IS" BASIS,
12- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13- * See the License for the specific language governing permissions and
14- * limitations under the License.
15- */
16-
17-package com.android.vending.licensing;
18-
19-import com.android.vending.licensing.ILicenseResultListener;
20-
21-oneway interface ILicensingService {
22- void checkLicense(long nonce, String packageName, in ILicenseResultListener listener);
23-}
--- a/samples/MarketLicensing/src/com/android/vending/licensing/LicenseChecker.java
+++ /dev/null
@@ -1,165 +0,0 @@
1-/*
2- * Copyright (C) 2010 The Android Open Source Project
3- *
4- * Licensed under the Apache License, Version 2.0 (the "License");
5- * you may not use this file except in compliance with the License.
6- * You may obtain a copy of the License at
7- *
8- * http://www.apache.org/licenses/LICENSE-2.0
9- *
10- * Unless required by applicable law or agreed to in writing, software
11- * distributed under the License is distributed on an "AS IS" BASIS,
12- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13- * See the License for the specific language governing permissions and
14- * limitations under the License.
15- */
16-
17-package com.android.vending.licensing;
18-
19-import java.security.SecureRandom;
20-
21-import android.content.ComponentName;
22-import android.content.Context;
23-import android.content.Intent;
24-import android.content.ServiceConnection;
25-import android.content.pm.PackageManager.NameNotFoundException;
26-import android.os.IBinder;
27-import android.os.RemoteException;
28-import android.util.Log;
29-
30-import com.android.vending.licensing.LicenseCheckerCallback.ApplicationErrorCode;
31-import com.android.vending.licensing.Policy.LicenseResponse;
32-
33-/**
34- * Client library for Android Market license verifications.
35- *
36- * The LicenseChecker is configured via a {@link Policy} which contains the
37- * logic to determine whether a user should have access to the application.
38- * For example, the Policy can define a threshold for allowable number of
39- * server or client failures before the library reports the user as not having
40- * access.
41- *
42- * This library is not thread-safe. Multiple, concurrent checks will result in
43- * an error.
44- */
45-public class LicenseChecker implements ServiceConnection {
46- private static final String TAG = "LicenseChecker";
47-
48- private static final SecureRandom RANDOM = new SecureRandom();
49-
50- private ILicensingService mService;
51-
52- /** Validator for the request in progress. */
53- private LicenseValidator mValidator;
54-
55- private final Context mContext;
56- private final Policy mPolicy;
57- /** Listener for service (IPC) calls. */
58- private final ResultListener mListener;
59- private final String mPackageName;
60- private final String mVersionCode;
61-
62- public LicenseChecker(Context context, Policy policy) {
63- mContext = context;
64- mPolicy = policy;
65- mListener = new ResultListener();
66- mPackageName = mContext.getPackageName();
67- mVersionCode = getVersionCode(context, mPackageName);
68- }
69-
70- private boolean isInProgress() {
71- return mValidator != null;
72- }
73-
74- /**
75- * Checks if the user should have access to the app.
76- *
77- * @param callback
78- */
79- public synchronized void checkAccess(LicenseCheckerCallback callback) {
80- if (isInProgress()) {
81- callback.applicationError(ApplicationErrorCode.CHECK_IN_PROGRESS);
82- }
83-
84- mValidator = new LicenseValidator(mPolicy, callback, generateNonce(), mPackageName,
85- mVersionCode);
86-
87- Log.i(TAG, "Binding to licensing service.");
88- boolean bindResult = mContext.bindService(new Intent(ILicensingService.class.getName()),
89- this, // ServiceConnection.
90- Context.BIND_AUTO_CREATE);
91-
92- if (!bindResult) {
93- Log.e(TAG, "Could not bind to service.");
94- callback.dontAllow();
95- // No need to unbind at this point.
96- return;
97- }
98- }
99-
100- private class ResultListener extends ILicenseResultListener.Stub {
101- public void verifyLicense(int responseCode, String signedData, String signature) {
102- mValidator.verify(responseCode, signedData, signature);
103- cleanup();
104- }
105- }
106-
107- public void onServiceConnected(ComponentName name, IBinder service) {
108- mService = ILicensingService.Stub.asInterface(service);
109-
110- try {
111- Log.i(TAG, "Calling checkLicense on service for " + mValidator.getPackageName());
112- mService.checkLicense(mValidator.getNonce(), mValidator.getPackageName(), mListener);
113- } catch (RemoteException e) {
114- Log.w(TAG, "RemoteException in checkLicense call.", e);
115- handleServiceConnectionError();
116- // cleanup unbinds service.
117- cleanup();
118- }
119- }
120-
121- public void onServiceDisconnected(ComponentName name) {
122- // Called when the connection with the service has been
123- // unexpectedly disconnected. That is, Market crashed.
124- Log.w(TAG, "Service unexpectedly disconnected.");
125- handleServiceConnectionError();
126- // cleanup unbinds service.
127- cleanup();
128- }
129-
130- private void handleServiceConnectionError() {
131- if (mPolicy.allowAccess(LicenseResponse.CLIENT_RETRY)) {
132- mValidator.getCallback().allow();
133- } else {
134- mValidator.getCallback().dontAllow();
135- }
136- }
137-
138- /** Resets request state. */
139- private synchronized void cleanup() {
140- mContext.unbindService(this);
141- mValidator = null;
142- }
143-
144- /** Generates a nonce (number used once). */
145- private int generateNonce() {
146- return RANDOM.nextInt();
147- }
148-
149- /**
150- * Get version code for the application package name.
151- *
152- * @param context
153- * @param packageName application package name
154- * @return the version code or empty string if package not found
155- */
156- private static String getVersionCode(Context context, String packageName) {
157- try {
158- return String.valueOf(context.getPackageManager().getPackageInfo(packageName, 0).
159- versionCode);
160- } catch (NameNotFoundException e) {
161- Log.e(TAG, "Package not found. could not get version code.");
162- return "";
163- }
164- }
165-}
--- a/samples/MarketLicensing/src/com/android/vending/licensing/LicenseCheckerCallback.java
+++ /dev/null
@@ -1,55 +0,0 @@
1-/*
2- * Copyright (C) 2010 The Android Open Source Project
3- *
4- * Licensed under the Apache License, Version 2.0 (the "License");
5- * you may not use this file except in compliance with the License.
6- * You may obtain a copy of the License at
7- *
8- * http://www.apache.org/licenses/LICENSE-2.0
9- *
10- * Unless required by applicable law or agreed to in writing, software
11- * distributed under the License is distributed on an "AS IS" BASIS,
12- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13- * See the License for the specific language governing permissions and
14- * limitations under the License.
15- */
16-
17-package com.android.vending.licensing;
18-
19-/**
20- * Callback for the license checker library.
21- *
22- * Upon checking with the Market server and conferring with the policy, the
23- * library calls a appropriate callback method to communicate the result.
24- */
25-public interface LicenseCheckerCallback {
26-
27- /**
28- * Allow use. App should proceed as normal.
29- */
30- public void allow();
31-
32- /**
33- * Don't allow use. App should inform user and take appropriate action.
34- */
35- public void dontAllow();
36-
37- /** Application error codes. */
38- public enum ApplicationErrorCode {
39- /** Package is not installed. */
40- INVALID_PACKAGE_NAME,
41- /** Requested for a package that is not the current app. */
42- NON_MATCHING_UID,
43- /** Market does not know about the package. */
44- NOT_MARKET_MANAGED,
45- /** A previous check request is already in progress.
46- * Only one check is allowed at a time. */
47- CHECK_IN_PROGRESS
48- }
49-
50- /**
51- * Error in application code. Caller did not call or set up license
52- * checker correctly. Should be considered fatal.
53- */
54- public void applicationError(ApplicationErrorCode errorCode);
55-}
--- a/samples/MarketLicensing/src/com/android/vending/licensing/LicenseValidator.java
+++ /dev/null
@@ -1,165 +0,0 @@
1-/*
2- * Copyright (C) 2010 The Android Open Source Project
3- *
4- * Licensed under the Apache License, Version 2.0 (the "License");
5- * you may not use this file except in compliance with the License.
6- * You may obtain a copy of the License at
7- *
8- * http://www.apache.org/licenses/LICENSE-2.0
9- *
10- * Unless required by applicable law or agreed to in writing, software
11- * distributed under the License is distributed on an "AS IS" BASIS,
12- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13- * See the License for the specific language governing permissions and
14- * limitations under the License.
15- */
16-
17-package com.android.vending.licensing;
18-
19-import android.util.Log;
20-
21-import com.android.vending.licensing.LicenseCheckerCallback.ApplicationErrorCode;
22-import com.android.vending.licensing.Policy.LicenseResponse;
23-
24-/**
25- * Contains data related to a licensing request and methods to verify
26- * and process the response.
27- */
28-class LicenseValidator {
29- private static final String TAG = "LicenseValidator";
30-
31- // Server response codes.
32- private static final int LICENSED = 0x0;
33- private static final int NOT_LICENSED = 0x1;
34- private static final int LICENSED_OLD_KEY = 0x2;
35- private static final int ERROR_NOT_MARKET_MANAGED = 0x3;
36- private static final int ERROR_INVALID_KEYS = 0x4;
37- private static final int ERROR_OVER_QUOTA = 0x5;
38-
39- private static final int ERROR_CONTACTING_SERVER = 0x101;
40- private static final int ERROR_INVALID_PACKAGE_NAME = 0x102;
41- private static final int ERROR_NON_MATCHING_UID = 0x103;
42-
43- private final Policy mPolicy;
44- private final LicenseCheckerCallback mCallback;
45- private final int mNonce;
46- private final String mPackageName;
47- private final String mVersionCode;
48-
49- LicenseValidator(Policy policy, LicenseCheckerCallback callback, int nonce, String packageName,
50- String versionCode) {
51- mPolicy = policy;
52- mCallback = callback;
53- mNonce = nonce;
54- mPackageName = packageName;
55- mVersionCode = versionCode;
56- }
57-
58- public LicenseCheckerCallback getCallback() {
59- return mCallback;
60- }
61-
62- public int getNonce() {
63- return mNonce;
64- }
65-
66- public String getPackageName() {
67- return mPackageName;
68- }
69-
70- /**
71- * Verifies the response from server and calls appropriate callback method.
72- *
73- * @param responseCode server response code
74- * @param signedData signed data from server
75- * @param signature server signature
76- */
77- public void verify(int responseCode, String signedData, String signature) {
78- // Parse and validate response.
79- // TODO(jyum): decode data with signature.
80- // TODO(jyum): verify timestamp is within reason. However, relying
81- // on device clock may lead to problems?
82- ResponseData data;
83- try {
84- data = ResponseData.parse(signedData);
85- } catch (IllegalArgumentException e) {
86- Log.e(TAG, "Could not parse response.");
87- handleInvalidResponse();
88- return;
89- }
90-
91- if (data.responseCode != responseCode) {
92- Log.e(TAG, "Response codes don't match.");
93- handleInvalidResponse();
94- return;
95- }
96-
97- if (data.nonce != mNonce) {
98- Log.e(TAG, "Nonce doesn't match.");
99- handleInvalidResponse();
100- return;
101- }
102-
103- if (!data.packageName.equals(mPackageName)) {
104- Log.e(TAG, "Package name doesn't match.");
105- handleInvalidResponse();
106- return;
107- }
108-
109- if (!data.versionCode.equals(mVersionCode)) {
110- Log.e(TAG, "Version codes don't match.");
111- handleInvalidResponse();
112- return;
113- }
114-
115- switch (responseCode) {
116- case LICENSED:
117- case LICENSED_OLD_KEY:
118- handleResponse(LicenseResponse.LICENSED);
119- break;
120- case NOT_LICENSED:
121- handleResponse(LicenseResponse.NOT_LICENSED);
122- break;
123- case ERROR_CONTACTING_SERVER:
124- handleResponse(LicenseResponse.CLIENT_RETRY);
125- break;
126- case ERROR_INVALID_KEYS:
127- case ERROR_OVER_QUOTA:
128- handleResponse(LicenseResponse.SERVER_RETRY);
129- break;
130- case ERROR_INVALID_PACKAGE_NAME:
131- handleApplicationError(ApplicationErrorCode.INVALID_PACKAGE_NAME);
132- break;
133- case ERROR_NON_MATCHING_UID:
134- handleApplicationError(ApplicationErrorCode.NON_MATCHING_UID);
135- break;
136- case ERROR_NOT_MARKET_MANAGED:
137- handleApplicationError(ApplicationErrorCode.NOT_MARKET_MANAGED);
138- break;
139- default:
140- Log.e(TAG, "Unknown response code for license check.");
141- handleInvalidResponse();
142- }
143- }
144-
145- /**
146- * Confers with policy and calls appropriate callback method.
147- *
148- * @param response
149- */
150- private void handleResponse(LicenseResponse response) {
151- if (mPolicy.allowAccess(response)) {
152- mCallback.allow();
153- } else {
154- mCallback.dontAllow();
155- }
156- }
157-
158- private void handleApplicationError(ApplicationErrorCode code) {
159- mCallback.applicationError(code);
160- }
161-
162- private void handleInvalidResponse() {
163- mCallback.dontAllow();
164- }
165-}
--- a/samples/MarketLicensing/src/com/android/vending/licensing/Policy.java
+++ /dev/null
@@ -1,55 +0,0 @@
1-/*
2- * Copyright (C) 2010 The Android Open Source Project
3- *
4- * Licensed under the Apache License, Version 2.0 (the "License");
5- * you may not use this file except in compliance with the License.
6- * You may obtain a copy of the License at
7- *
8- * http://www.apache.org/licenses/LICENSE-2.0
9- *
10- * Unless required by applicable law or agreed to in writing, software
11- * distributed under the License is distributed on an "AS IS" BASIS,
12- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13- * See the License for the specific language governing permissions and
14- * limitations under the License.
15- */
16-
17-package com.android.vending.licensing;
18-
19-/**
20- * Policy used by {@link LicenseChecker} to determine whether a user should
21- * have access to the application.
22- */
23-public interface Policy {
24-
25- /**
26- * Result of a license check.
27- */
28- public enum LicenseResponse {
29- /**
30- * User is licensed to use the app.
31- */
32- LICENSED,
33- /**
34- * User is not licensed to use the app.
35- */
36- NOT_LICENSED,
37- /**
38- * Retryable error on the client side e.g. no network.
39- */
40- CLIENT_RETRY,
41- /**
42- * Retryable error on the server side e.g. application is over request
43- * quota.
44- */
45- SERVER_RETRY,
46- }
47-
48- /**
49- * Determines whether the user should be allowed access.
50- *
51- * @param response result of the license check request
52- * @return true iff access should be allowed
53- */
54- boolean allowAccess(LicenseResponse response);
55-}
--- a/samples/MarketLicensing/src/com/android/vending/licensing/ResponseData.java
+++ /dev/null
@@ -1,84 +0,0 @@
1-/*
2- * Copyright (C) 2010 The Android Open Source Project
3- *
4- * Licensed under the Apache License, Version 2.0 (the "License");
5- * you may not use this file except in compliance with the License.
6- * You may obtain a copy of the License at
7- *
8- * http://www.apache.org/licenses/LICENSE-2.0
9- *
10- * Unless required by applicable law or agreed to in writing, software
11- * distributed under the License is distributed on an "AS IS" BASIS,
12- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13- * See the License for the specific language governing permissions and
14- * limitations under the License.
15- */
16-
17-package com.android.vending.licensing;
18-
19-import java.util.Iterator;
20-import java.util.regex.Pattern;
21-
22-import android.text.TextUtils;
23-
24-/**
25- * ResponseData from licensing server.
26- */
27-class ResponseData {
28-
29- public int responseCode;
30- public int nonce;
31- public String packageName;
32- public String versionCode;
33- public String userId;
34- public long timestamp;
35- /** Response-specific data. */
36- public String extra;
37-
38- /**
39- * Parses response string into ResponseData.
40- *
41- * @param responseData response data string
42- * @throws IllegalArgumentException upon parsing error
43- * @return ResponseData object
44- */
45- public static ResponseData parse(String responseData) {
46- // Must parse out main response data and response-specific data.
47- TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter(':');
48- splitter.setString(responseData);
49- Iterator<String> it = splitter.iterator();
50- if (!it.hasNext()) {
51- throw new IllegalArgumentException("Blank response.");
52- }
53- final String mainData = it.next();
54-
55- // Response-specific (extra) data is optional.
56- String extraData = "";
57- if (it.hasNext()) {
58- extraData = it.next();
59- }
60-
61- String [] fields = TextUtils.split(mainData, Pattern.quote("|"));
62- if (fields.length < 5) {
63- throw new IllegalArgumentException("Wrong number of fields.");
64- }
65-
66- ResponseData data = new ResponseData();
67- data.extra = extraData;
68- data.responseCode = Integer.parseInt(fields[0]);
69- data.nonce = Integer.parseInt(fields[1]);
70- data.packageName = fields[2];
71- data.versionCode = fields[3];
72- // TODO(jyum): userId is not there yet.
73- // data.userId = fields[4];
74- data.timestamp = Long.parseLong(fields[4]);
75-
76- return data;
77- }
78-
79- @Override
80- public String toString() {
81- return TextUtils.join("|", new Object [] { responseCode, nonce, packageName, versionCode,
82- userId, timestamp });
83- }
84-}
--- a/samples/MarketLicensing/src/com/android/vending/licensing/StrictPolicy.java
+++ /dev/null
@@ -1,30 +0,0 @@
1-/*
2- * Copyright (C) 2010 The Android Open Source Project
3- *
4- * Licensed under the Apache License, Version 2.0 (the "License");
5- * you may not use this file except in compliance with the License.
6- * You may obtain a copy of the License at
7- *
8- * http://www.apache.org/licenses/LICENSE-2.0
9- *
10- * Unless required by applicable law or agreed to in writing, software
11- * distributed under the License is distributed on an "AS IS" BASIS,
12- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13- * See the License for the specific language governing permissions and
14- * limitations under the License.
15- */
16-
17-package com.android.vending.licensing;
18-
19-/**
20- * Strict policy.
21- *
22- * Should never be used in a real application as it strictly disallows access
23- * upon retryable errors such as no connection present.
24- */
25-public class StrictPolicy implements Policy {
26-
27- public boolean allowAccess(LicenseResponse response) {
28- return LicenseResponse.LICENSED == response;
29- }
30-}