Skip to content

Commit

Permalink
Merge pull request #1015 from Microsoft/feature/identity
Browse files Browse the repository at this point in the history
Merge Identity to develop
  • Loading branch information
guperrot committed Mar 21, 2019
2 parents 6b2d512 + 4477c1d commit 34e5d22
Show file tree
Hide file tree
Showing 84 changed files with 3,909 additions and 316 deletions.
3 changes: 3 additions & 0 deletions apps/sasquatch/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,15 @@ repositories {
dependencies {
implementation "com.android.support:support-v4:${rootProject.ext.supportLibVersion}"
implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
implementation "com.android.support:customtabs:${rootProject.ext.supportLibVersion}"

projectDependencyImplementation project(':sdk:appcenter-analytics')
projectDependencyImplementation project(':sdk:appcenter-crashes')
projectDependencyImplementation project(':sdk:appcenter-distribute')
projectDependencyImplementation project(':sdk:appcenter-identity')
projectDependencyImplementation project(':sdk:appcenter-push')
projectDependencyImplementation project(':sdk:appcenter-rum')
projectDependencyImplementation project(':sdk:appcenter-identity')

def appCenterSdkVersion = "1.11.4"
//noinspection GradleDependency
Expand Down
5 changes: 5 additions & 0 deletions apps/sasquatch/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,8 @@
-keepclasseswithmembers class com.microsoft.appcenter.ingestion.models.Device {
public ** get*();
}

# TODO: Below config is temporary. Please remove this once we have binaries ready in jcenter.
-keep public class com.microsoft.appcenter.identity.Identity {
*;
}
16 changes: 15 additions & 1 deletion apps/sasquatch/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
android:allowBackup="false"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:networkSecurityConfig="@xml/network_security_config"
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:ignore="AllowBackup,GoogleAppIndexingWarning,UnpackedNativeCode">
tools:ignore="AllowBackup,GoogleAppIndexingWarning,UnpackedNativeCode"
tools:targetApi="n">
<activity
android:name=".activities.MainActivity"
android:launchMode="singleTop">
Expand Down Expand Up @@ -63,6 +65,18 @@
<activity
android:name=".activities.MSALoginActivity"
android:label="@string/msa_title" />
<activity android:name="com.microsoft.identity.client.BrowserTabActivity">
<intent-filter>
<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />

<data
android:host="auth"
android:scheme="msal9e0d97c1-7838-46d0-9dab-1a0ef66aec6e" />
</intent-filter>
</activity>

<!-- Set default notification icon and color. -->
<meta-data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,27 @@
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.ListView;

import com.microsoft.appcenter.analytics.AuthenticationProvider;
import com.microsoft.appcenter.sasquatch.R;
import com.microsoft.appcenter.sasquatch.features.TestFeatures;
import com.microsoft.appcenter.sasquatch.features.TestFeaturesListAdapter;
import com.microsoft.appcenter.utils.async.AppCenterConsumer;
import com.microsoft.appcenter.utils.async.AppCenterFuture;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;

import static com.microsoft.appcenter.sasquatch.activities.MainActivity.LOG_TAG;

public class AuthenticationProviderActivity extends AppCompatActivity {

private boolean mUserLeaving;

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -44,6 +52,58 @@ public void onClick(View v) {
startMSALoginActivity(AuthenticationProvider.Type.MSA_DELEGATE);
}
}));

/* TODO remove reflection once Identity published to jCenter. */
try {
final Class<?> identity = Class.forName("com.microsoft.appcenter.identity.Identity");
featureList.add(new TestFeatures.TestFeature(R.string.b2c_sign_in_title, R.string.b2c_sign_in_description, new View.OnClickListener() {

/* TODO remove reflection once Identity published to jCenter. Remove this annotation too. */
@SuppressWarnings("unchecked")
@Override
public void onClick(View v) {
try {
AppCenterFuture<Object> future = (AppCenterFuture<Object>) identity.getMethod("signIn").invoke(null);
future.thenAccept(new AppCenterConsumer<Object>() {

@Override
public void accept(Object signInResult) {
try {
Class<?> signInResultClass = signInResult.getClass();
Method getException = signInResultClass.getMethod("getException");
Exception exception = (Exception) getException.invoke(signInResult);
if (exception != null) {
throw exception;
}
Method getUserInformation = signInResultClass.getMethod("getUserInformation");
Object userInformation = getUserInformation.invoke(signInResult);
String accountId = (String) userInformation.getClass().getMethod("getAccountId").invoke(userInformation);
Log.i(LOG_TAG, "Identity.signIn succeeded, accountId=" + accountId);
} catch (Exception e) {
Log.e(LOG_TAG, "Identity.signIn failed", e);
}
}
});
} catch (Exception e) {
Log.e(LOG_TAG, "Identity.signIn failed", e);
}
}
}));
featureList.add(new TestFeatures.TestFeature(R.string.b2c_sign_out_title, R.string.b2c_sign_out_description, new View.OnClickListener() {

/* TODO remove reflection once Identity published to jCenter. Remove this annotation too. */
@SuppressWarnings("unchecked")
@Override
public void onClick(View v) {
try {
identity.getMethod("signOut").invoke(null);
} catch (Exception e) {
Log.e(LOG_TAG, "Identity.signOut failed", e);
}
}
}));
} catch (ClassNotFoundException ignore) {
}
ListView listView = findViewById(R.id.list);
listView.setAdapter(new TestFeaturesListAdapter(featureList));
listView.setOnItemClickListener(TestFeatures.getOnItemClickListener());
Expand All @@ -52,12 +112,21 @@ public void onClick(View v) {
private void startMSALoginActivity(AuthenticationProvider.Type type) {
Intent intent = new Intent(getApplication(), MSALoginActivity.class);
intent.putExtra(AuthenticationProvider.Type.class.getName(), type);
startActivityForResult(intent, 0);
startActivity(intent);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
finish();
protected void onUserLeaveHint() {
mUserLeaving = true;
}

@Override
protected void onRestart() {

/* When coming back from browser, finish this intermediate menu screen too. */
super.onRestart();
if (mUserLeaving) {
finish();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,10 @@
import com.microsoft.appcenter.analytics.AuthenticationProvider;
import com.microsoft.appcenter.http.DefaultHttpClient;
import com.microsoft.appcenter.http.HttpClient;
import com.microsoft.appcenter.http.HttpClientNetworkStateHandler;
import com.microsoft.appcenter.http.HttpClientRetryer;
import com.microsoft.appcenter.http.HttpException;
import com.microsoft.appcenter.http.ServiceCallback;
import com.microsoft.appcenter.sasquatch.R;
import com.microsoft.appcenter.utils.AppCenterLog;
import com.microsoft.appcenter.utils.NetworkStateHelper;

import org.json.JSONException;
import org.json.JSONObject;
Expand Down Expand Up @@ -323,8 +320,14 @@ public void onBeforeCalling(URL url, Map<String, String> headers) {
},
new ServiceCallback() {

@Override
/* TODO remove this method once Identity published to jCenter. */
public void onCallSucceeded(String payload) {
onCallSucceeded(payload, null);
}

/* TODO add @Override once Identity published to jCenter. Remove also suppress warnings. */
@SuppressWarnings("WeakerAccess")
public void onCallSucceeded(String payload, @SuppressWarnings("unused") Map<String, String> headers) {
try {
JSONObject response = new JSONObject(payload);
String userId = response.getString(USER_ID);
Expand Down Expand Up @@ -367,8 +370,14 @@ public void onBeforeCalling(URL url, Map<String, String> headers) {
},
new ServiceCallback() {

@Override
/* TODO remove this method once Identity published to jCenter. */
public void onCallSucceeded(String payload) {
onCallSucceeded(payload, null);
}

/* TODO add @Override once Identity published to jCenter. Remove also suppress warnings. */
@SuppressWarnings("WeakerAccess")
public void onCallSucceeded(String payload, @SuppressWarnings("unused") Map<String, String> headers) {
try {
JSONObject response = new JSONObject(payload);
String accessToken = response.getString("access_token");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import android.widget.Toast;

import com.microsoft.appcenter.AppCenter;
import com.microsoft.appcenter.AppCenterService;
import com.microsoft.appcenter.analytics.Analytics;
import com.microsoft.appcenter.analytics.AnalyticsPrivateHelper;
import com.microsoft.appcenter.analytics.channel.AnalyticsListener;
Expand Down Expand Up @@ -140,6 +141,21 @@ protected void onCreate(Bundle savedInstanceState) {
Distribute.setApiUrl(apiUrl);
}

/* Set identity config url. */
String configUrl = getString(R.string.identity_config_url);
if (!TextUtils.isEmpty(configUrl)) {

/* TODO once Identity released to jCenter, use Identity.setConfigUrl directly. */
try {
Class<?> identity = Class.forName("com.microsoft.appcenter.identity.Identity");
identity.getMethod("setConfigUrl", String.class).invoke(null, configUrl);
} catch (ClassNotFoundException ignored) {
} catch (NoSuchMethodException ignored) {
} catch (Exception e) {
throw new RuntimeException(e);
}
}

/* Set push sender ID the old way for testing without firebase lib. */
setSenderId();

Expand Down Expand Up @@ -328,6 +344,16 @@ static void startAppCenter(Application application, String startTypeString) {
return;
}
AppCenter.start(application, appIdArg, Analytics.class, Crashes.class, Distribute.class, Push.class);

/* TODO once Identity released to jCenter, use Identity.class directly in the start calls. */
try {
String className = "com.microsoft.appcenter.identity.Identity";

@SuppressWarnings("unchecked")
Class<AppCenterService> identity = (Class<AppCenterService>) Class.forName(className);
AppCenter.start(identity);
} catch (ClassNotFoundException ignored) {
}
}

public enum StartType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

package com.microsoft.appcenter.sasquatch.activities;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
Expand All @@ -17,7 +18,6 @@
import android.os.FileObserver;
import android.preference.CheckBoxPreference;
import android.preference.Preference;
import android.preference.PreferenceGroup;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.text.InputType;
Expand All @@ -36,7 +36,6 @@
import com.microsoft.appcenter.crashes.Crashes;
import com.microsoft.appcenter.distribute.Distribute;
import com.microsoft.appcenter.push.Push;
import com.microsoft.appcenter.sasquatch.BuildConfig;
import com.microsoft.appcenter.sasquatch.R;
import com.microsoft.appcenter.sasquatch.activities.MainActivity.StartType;
import com.microsoft.appcenter.sasquatch.eventfilter.EventFilter;
Expand Down Expand Up @@ -260,6 +259,56 @@ public boolean isEnabled() {
return Push.isEnabled().get();
}
});

/* Identity. */
/*
* TODO: change to real implementation when released.
*
* initCheckBoxSetting(R.string.appcenter_identity_state_key, R.string.appcenter_identity_state_summary_enabled, R.string.appcenter_identity_state_summary_disabled, new HasEnabled() {
*
* @Override
* public void setEnabled(boolean enabled) {
* Identity.setEnabled(enabled);
* }
*
* @Override
* public boolean isEnabled() {
* return Identity.isEnabled().get();
* }
* });
*/

try {
@SuppressWarnings("unchecked") final Class<? extends AppCenterService> identity = (Class<? extends AppCenterService>) Class.forName("com.microsoft.appcenter.identity.Identity");
final Method isEnabled = identity.getMethod("isEnabled");
final Method setEnabled = identity.getMethod("setEnabled", boolean.class);
initCheckBoxSetting(R.string.appcenter_identity_state_key, R.string.appcenter_identity_state_summary_enabled, R.string.appcenter_identity_state_summary_disabled, new HasEnabled() {

@Override
@SuppressWarnings({"unchecked", "JavaReflectionMemberAccess", "JavaReflectionInvocation"})
public void setEnabled(boolean enabled) {
try {
setEnabled.invoke(null, enabled);
} catch (Exception e) {
throw new RuntimeException(e);
}
}

@Override
@SuppressWarnings({"unchecked", "JavaReflectionMemberAccess", "JavaReflectionInvocation"})
public boolean isEnabled() {
try {
AppCenterFuture<Boolean> result = (AppCenterFuture<Boolean>) isEnabled.invoke(null);
return result.get();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
});
} catch (Exception e) {
getPreferenceScreen().removePreference(findPreference(getString(R.string.identity_key)));
}

initCheckBoxSetting(R.string.appcenter_push_firebase_state_key, R.string.appcenter_push_firebase_summary_enabled, R.string.appcenter_push_firebase_summary_disabled, new HasEnabled() {

@Override
Expand Down Expand Up @@ -478,6 +527,7 @@ public void onReset() {
});
initClickableSetting(R.string.clear_crash_user_confirmation_key, new Preference.OnPreferenceClickListener() {

@SuppressLint("VisibleForTests")
@Override
public boolean onPreferenceClick(Preference preference) {
SharedPreferences appCenterPreferences = getActivity().getSharedPreferences("AppCenter", Context.MODE_PRIVATE);
Expand Down
1 change: 1 addition & 0 deletions apps/sasquatch/src/main/res/values/env.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
<string name="log_url" tools:ignore="MissingTranslation" />
<string name="install_url" tools:ignore="MissingTranslation" />
<string name="api_url" tools:ignore="MissingTranslation" />
<string name="identity_config_url" tools:ignore="MissingTranslation" />
<string name="rum_key" tools:ignore="MissingTranslation" />
</resources>
8 changes: 8 additions & 0 deletions apps/sasquatch/src/main/res/values/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@
<string name="push_key" tools:ignore="MissingTranslation">appcenter_push</string>
<string name="push_title" tools:ignore="MissingTranslation">Push</string>

<string name="identity_key" tools:ignore="MissingTranslation">appcenter_identity</string>
<string name="identity_title" tools:ignore="MissingTranslation">Identity</string>

<string name="appcenter_push_firebase_state_key" tools:ignore="MissingTranslation">appcenter_push_firebase_state_key</string>
<string name="appcenter_push_firebase_state_title" tools:ignore="MissingTranslation">Firebase analytics state</string>
<string name="appcenter_push_firebase_summary_enabled" tools:ignore="MissingTranslation">Firebase analytics is enabled</string>
Expand All @@ -74,6 +77,11 @@
<string name="appcenter_push_state_summary_enabled" tools:ignore="MissingTranslation">Push is enabled</string>
<string name="appcenter_push_state_summary_disabled" tools:ignore="MissingTranslation">Push is disabled</string>

<string name="appcenter_identity_state_key" tools:ignore="MissingTranslation">appcenter_identity_state_key</string>
<string name="appcenter_identity_state_title" tools:ignore="MissingTranslation">Identity state</string>
<string name="appcenter_identity_state_summary_enabled" tools:ignore="MissingTranslation">Identity is enabled</string>
<string name="appcenter_identity_state_summary_disabled" tools:ignore="MissingTranslation">Identity is disabled</string>

<string name="real_user_measurements_key" tools:ignore="MissingTranslation">appcenter_rum</string>
<string name="real_user_measurements_title" tools:ignore="MissingTranslation">Real User Measurements</string>

Expand Down
8 changes: 6 additions & 2 deletions apps/sasquatch/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,13 @@
<string name="signed_in_cookie" tools:ignore="MissingTranslation">Clicking sign in will get token without prompt with cookie. Sign out to see prompt again.</string>
<string name="msa_title" tools:ignore="MissingTranslation">MSA authentication</string>
<string name="msa_compact_title" tools:ignore="MissingTranslation">MSA compact ticket</string>
<string name="msa_compact_description" tools:ignore="MissingTranslation">For first party applications</string>
<string name="msa_compact_description" tools:ignore="MissingTranslation">One collector userId from MSA whitelisted.</string>
<string name="msa_delegate_title" tools:ignore="MissingTranslation">MSA delegate ticket</string>
<string name="msa_delegate_description" tools:ignore="MissingTranslation">For third party applications</string>
<string name="msa_delegate_description" tools:ignore="MissingTranslation">One collector userId from MSA third-party.</string>
<string name="b2c_sign_in_title" tools:ignore="MissingTranslation">Azure B2C ticket</string>
<string name="b2c_sign_in_description" tools:ignore="MissingTranslation">For Identity module in App Center.</string>
<string name="b2c_sign_out_title" tools:ignore="MissingTranslation">Sign out</string>
<string name="b2c_sign_out_description" tools:ignore="MissingTranslation">For Identity module in App Center.</string>
<string name="max_storage_size_change_success" tools:ignore="MissingTranslation">Max storage size has changed to %s successfully. Check SDK logs for actual size of storage.</string>
<string name="max_storage_size_change_failed" tools:ignore="MissingTranslation">Failed to change max storage size.</string>
<string name="size_in_bytes" tools:ignore="MissingTranslation">Size in bytes</string>
Expand Down
Loading

0 comments on commit 34e5d22

Please sign in to comment.