Skip to content

Commit

Permalink
Merge pull request #15 from jefftharris/feature/12-onedrive-upgrade
Browse files Browse the repository at this point in the history
Update OneDrive libraries

Fixes #12
  • Loading branch information
jefftharris authored Jan 5, 2025
2 parents 847ece3 + de2d066 commit 7b6a676
Show file tree
Hide file tree
Showing 35 changed files with 1,497 additions and 698 deletions.
3 changes: 3 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
# Default value: -Xmx10248m -XX:MaxPermSize=256m

# suppress inspection "UnusedProperty"
org.gradle.jvmargs=-Xmx2048m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
org.gradle.jvmargs=-Xmx8g -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8

android.enableJetifier=true
android.useAndroidX=true
Expand Down
601 changes: 527 additions & 74 deletions gradle/verification-metadata.xml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@ public static synchronized void removeListener(Listener listener)
}
}

/**
* Log a formatted message at error level
*/
public static void error(@NonNull String tag,
@PrintFormat String fmt,
Object... args)
{
Log.e(tag, String.format(fmt, args));
}

/**
* Log a formatted message at error level
*/
Expand Down
12 changes: 7 additions & 5 deletions lib/src/main/java/com/jefftharris/passwdsafe/lib/Utils.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (©) 2016 Jeff Harris <[email protected]>
* Copyright (©) 2016-2024 Jeff Harris <[email protected]>
* All rights reserved. Use of the code is allowed under the
* Artistic License 2.0 terms, as specified in the LICENSE file
* distributed with this code, or available from
Expand All @@ -16,14 +16,15 @@
import android.content.Context;
import android.text.format.DateUtils;
import android.util.Log;
import androidx.annotation.NonNull;

/**
* The Utils class provides general utilities
*/
public final class Utils
{
/** Format a date according to the current locale settings */
public static String formatDate(Date date, Context ctx)
public static String formatDate(@NonNull Date date, Context ctx)
{
return formatDate(date.getTime(), ctx);
}
Expand Down Expand Up @@ -60,10 +61,11 @@ public static String formatDate(long date, Context ctx,


/** Copy the input stream to the output */
public static int copyStream(InputStream is, OutputStream os)
public static long copyStream(@NonNull InputStream is,
@NonNull OutputStream os)
throws IOException
{
int streamSize = 0;
long streamSize = 0;
byte[] buf = new byte[4096];
int len;
while ((len = is.read(buf)) > 0) {
Expand All @@ -75,7 +77,7 @@ public static int copyStream(InputStream is, OutputStream os)


/** Close the streams */
public static void closeStreams(Closeable... cs)
public static void closeStreams(@NonNull Closeable... cs)
{
for (Closeable c: cs) {
try {
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.

This file was deleted.

15 changes: 8 additions & 7 deletions sync/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ android {
compileSdk 34
defaultConfig {
applicationId "com.jefftharris.passwdsafe.sync"
minSdkVersion 21
minSdkVersion 26
resourceConfigurations += ['de', 'fr', 'nb']
targetSdkVersion 34
// <major><minor><bugfix><beta/extra>
Expand All @@ -27,6 +27,8 @@ android {
buildTypes {
debug {
debuggable true
// Uncomment below option to minify during debug development
// minifyEnabled true
proguardFiles += getDefaultProguardFile(
'proguard-android-optimize.txt')
proguardFiles += 'proguard-rules.pro'
Expand All @@ -38,6 +40,8 @@ android {
'proguard-android-optimize.txt')
proguardFiles += 'proguard-rules.pro'
proguardFiles += 'proguard-google-api-client.pro'
// Uncomment below to run minified release build in emulator
// signingConfig signingConfigs.debug
}
}
packagingOptions {
Expand Down Expand Up @@ -77,13 +81,10 @@ dependencies {
exclude group: 'com.google.guava'
}
// OneDrive
implementation 'com.microsoft.graph:msgraph-sdk-android:1.7.0'
implementation('com.microsoft.identity.client:msal:0.2.2') {
exclude group: 'com.android.support', module: 'appcompat-v7'
exclude group: 'com.google.com.gson'
implementation ('com.microsoft.identity.client:msal:5.8.2') {
exclude group: 'com.microsoft.device.display'
}
// Misc dependencies
implementation 'com.google.code.gson:gson:2.10.1'
implementation 'com.microsoft.graph:microsoft-graph:6.24.0'
}

secrets {
Expand Down
83 changes: 37 additions & 46 deletions sync/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,6 @@
#
# Apache http
#
-keep class org.apache.commons.httpclient.auth.BasicScheme
-keep class org.apache.commons.httpclient.auth.DigestScheme
-keep class org.apache.commons.httpclient.auth.NTLMScheme
-keep class org.apache.commons.httpclient.cookie.**

#
Expand All @@ -80,51 +77,12 @@
#
# OneDrive
#
-keep class com.microsoft.graph.extensions.Hashes
-keep class com.microsoft.identity.common.** { *; }
-keep class com.microsoft.identity.client.PublicClientApplication { *; }
-keep class com.microsoft.identity.client.PublicClientApplicationConfiguration { *; }
-keep class com.microsoft.identity.** { *; }
-keepclassmembers class com.microsoft.graph.extensions.** { *; }
# OneDrive MSAL library has its own proguard rules file. MS graph needs
# specific rules.

##---------------Begin: proguard configuration for MSAL --------
-keep class com.microsoft.identity.** { *; }
-keep class com.microsoft.device.display.** { *; }
# For the PageIterator, need the collection response classes
-keep class com.microsoft.graph.models.DriveItemCollectionResponse { *; }

##---------------Begin: proguard configuration for Nimbus ----------
#-keep class com.nimbusds.** { *; }

##---------------Begin: proguard configuration for Gson --------
# Gson uses generic type information stored in a class file when working with fields. Proguard
# removes such information by default, so configure it to keep all of it.
-keepattributes Signature

# For using GSON @Expose annotation
-keepattributes *Annotation*

# Gson specific classes
-dontwarn sun.misc.**
#-keep class com.google.gson.stream.** { *; }

# Application classes that will be serialized/deserialized over Gson
#-keep class com.google.gson.examples.android.model.** { <fields>; }

# Prevent proguard from stripping interface information from TypeAdapter, TypeAdapterFactory,
# JsonSerializer, JsonDeserializer instances (so they can be used in @JsonAdapter)
-keep class * extends com.google.gson.TypeAdapter
-keep class * implements com.google.gson.TypeAdapterFactory
-keep class * implements com.google.gson.JsonSerializer
-keep class * implements com.google.gson.JsonDeserializer

# Prevent R8 from leaving Data object members always null
-keepclassmembers,allowobfuscation class * {
@com.google.gson.annotations.SerializedName <fields>;
}

# Retain generic signatures of TypeToken and its subclasses with R8 version 3.0
# and higher. From https://github.com/google/gson/blob/main/examples/android-proguard-example/proguard.cfg
-keep,allowobfuscation,allowshrinking class com.google.gson.reflect.TypeToken
-keep,allowobfuscation,allowshrinking class * extends com.google.gson.reflect.TypeToken

#
# Retrofit library
Expand All @@ -145,3 +103,36 @@
-dontwarn okhttp3.**
-dontwarn com.squareup.okhttp.**
-dontwarn javax.servlet.**

#
# okhttp
#
-keepattributes Signature
-keepattributes *Annotation*
-keep class okhttp3.** { *; }
-keep interface okhttp3.** { *; }
-dontwarn okhttp3.**

#
# okio
#
-keep class sun.misc.**
-dontwarn java.nio.file.*
-dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
-dontwarn okio.**

#
# Extras required by build
#
-dontwarn com.google.auto.value.AutoValue
-dontwarn com.google.crypto.tink.subtle.Ed25519Sign$KeyPair
-dontwarn com.google.crypto.tink.subtle.Ed25519Sign
-dontwarn com.google.crypto.tink.subtle.Ed25519Verify
-dontwarn com.google.crypto.tink.subtle.X25519
-dontwarn com.google.crypto.tink.subtle.XChaCha20Poly1305
-dontwarn com.microsoft.device.display.DisplayMask
-dontwarn edu.umd.cs.findbugs.annotations.NonNull
-dontwarn edu.umd.cs.findbugs.annotations.Nullable
-dontwarn edu.umd.cs.findbugs.annotations.SuppressFBWarnings
-dontwarn reactor.blockhound.integration.BlockHoundIntegration

Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,14 @@
*/
package com.jefftharris.passwdsafe.sync;

import com.microsoft.identity.common.internal.providers.oauth2.AuthorizationStrategy;

/**
* Activity request codes
*/
public interface ActivityRequest
{
int DROPBOX_LINK = 1;
int BOX_AUTH = 2;
int ONEDRIVE_LINK = AuthorizationStrategy.BROWSER_FLOW;
int ONEDRIVE_LINK = 3;
//int OWNCLOUD_LINK = 4;
int PERMISSIONS = 5;
int APP_SETTINGS = 6;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public class MainActivity extends AppCompatActivity
private GDriveState itsGDriveState = GDriveState.OK;
private final SparseArray<Uri> itsAccountLinkUris = new SparseArray<>();
private boolean itsDropboxPendingAcctLink = false;
private boolean itsOnedrivePendingAcctLink = false;
private NewAccountTask<?> itsNewAccountTask = null;
private final List<AccountUpdateTask> itsUpdateTasks = new ArrayList<>();
private boolean itsIsRunning = false;
Expand Down Expand Up @@ -178,12 +179,23 @@ protected void onResumeFragments()
null, getAccountLinkUri(ActivityRequest.DROPBOX_LINK));
}

if (itsOnedrivePendingAcctLink) {
itsOnedrivePendingAcctLink = false;
itsNewAccountTask = getOnedriveProvider().finishAccountLink(
this, ActivityRequest.ONEDRIVE_LINK, Activity.RESULT_OK,
null, getAccountLinkUri(ActivityRequest.ONEDRIVE_LINK));
}

if (itsNewAccountTask != null) {
itsNewAccountTask.startTask(this, this);
itsNewAccountTask = null;
}
reloadProviders();
SyncApp.get(this).setSyncUpdateHandler(this);

for (ProviderType type: ProviderType.values()) {
ProviderFactory.getProvider(type, this).onResume();
}
}

@Override
Expand All @@ -196,12 +208,6 @@ public void onActivityResult(int requestCode, int resultCode, Intent data)
getAccountLinkUri(ActivityRequest.BOX_AUTH));
break;
}
case ActivityRequest.ONEDRIVE_LINK: {
itsNewAccountTask = getOnedriveProvider().finishAccountLink(
this, requestCode, resultCode, data,
getAccountLinkUri(ActivityRequest.ONEDRIVE_LINK));
break;
}
case ActivityRequest.GDRIVE_PLAY_LINK:
case ActivityRequest.GDRIVE_PLAY_LINK_PERMS: {
itsNewAccountTask = getGDrivePlayProvider().finishAccountLink(
Expand Down Expand Up @@ -355,6 +361,7 @@ private void onOnedriveChoose(Uri currProviderUri)
try {
onedriveProvider.startAccountLink(this,
ActivityRequest.ONEDRIVE_LINK);
itsOnedrivePendingAcctLink = true;
itsAccountLinkUris.put(ActivityRequest.ONEDRIVE_LINK,
currProviderUri);
} catch (Exception e) {
Expand Down Expand Up @@ -511,6 +518,7 @@ public void updateProviderSyncFreq(final Uri providerUri,
.startTask(this, this);
}

@Nullable
@Override
public SyncResults getProviderSyncResults(ProviderType type)
{
Expand All @@ -519,6 +527,7 @@ public SyncResults getProviderSyncResults(ProviderType type)
}

@Override
@Nullable
public CharSequence getProviderWarning(@NonNull ProviderType type)
{
CharSequence warning = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import android.net.Uri;

import androidx.annotation.Nullable;
import androidx.annotation.StringRes;

import com.jefftharris.passwdsafe.lib.ProviderType;
Expand Down Expand Up @@ -43,11 +44,13 @@ void updateProviderSyncFreq(Uri providerUri,
/**
* Get the results of the syncs for a provider
*/
@Nullable
SyncResults getProviderSyncResults(ProviderType type);

/**
* Get a warning message to show for the provider
*/
@Nullable
CharSequence getProviderWarning(ProviderType type);

/**
Expand Down
Loading

0 comments on commit 7b6a676

Please sign in to comment.