Skip to content

Commit

Permalink
Facebook Android SDK 4.26
Browse files Browse the repository at this point in the history
  • Loading branch information
lepouya committed Aug 25, 2017
1 parent 1ab3edd commit c491bb4
Show file tree
Hide file tree
Showing 19 changed files with 538 additions and 80 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.2'
classpath 'com.android.tools.build:gradle:2.3.3'
}
}

Expand Down
3 changes: 3 additions & 0 deletions facebook/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ dependencies {
compile 'com.android.support:customtabs:25.3.1'
compile 'com.parse.bolts:bolts-android:1.4.0'

// Third-party Dependencies
compile 'com.google.zxing:core:3.3.0'

// Unit Tests
testCompile 'junit:junit:4.12'
testCompile 'org.robolectric:robolectric:3.3'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@
package com.facebook;

final class FacebookSdkVersion {
public static final String BUILD = "4.25.0";
public static final String BUILD = "4.26.0";
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,27 @@

import android.annotation.TargetApi;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.net.nsd.NsdManager;
import android.net.nsd.NsdServiceInfo;
import android.os.Build;

import com.facebook.FacebookSdk;
import com.facebook.internal.FetchedAppSettingsManager;
import com.facebook.internal.SmartLoginOption;
import com.facebook.internal.Utility;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.MultiFormatWriter;
import com.google.zxing.WriterException;
import com.google.zxing.common.BitMatrix;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.EnumMap;
import java.util.HashMap;
import java.util.Map;

/**
* com.facebook.devicerequests.internal is solely for the use of other packages within the
Expand Down Expand Up @@ -88,6 +96,36 @@ public static boolean isAvailable() {
getSmartLoginOptions().contains(SmartLoginOption.Enabled);
}

public static Bitmap generateQRCode(final String url) {
Bitmap qrCode = null;
Map<EncodeHintType, Object> hints = new EnumMap<>(EncodeHintType.class);
hints.put(EncodeHintType.MARGIN, 2);
try {
BitMatrix matrix = new MultiFormatWriter()
.encode(url, BarcodeFormat.QR_CODE, 200, 200, hints);

int h = matrix.getHeight();
int w = matrix.getWidth();
int[] pixels = new int[h * w];

for (int i = 0; i < h; i++) {
int offset = i * w;
for (int j = 0; j < w; j++) {
pixels[offset + j] =
matrix.get(j, i) ? Color.BLACK : Color.WHITE;
}
}

qrCode = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
qrCode.setPixels(pixels, 0, w, 0, 0, w, h);

} catch (WriterException ignored) {
// ignored because exception would be thrown from ZXing library.
}

return qrCode;
}

public static void cleanUpAdvertisementService(String userCode) {
cleanUpAdvertisementServiceImpl(userCode);
}
Expand Down
4 changes: 2 additions & 2 deletions facebook/src/main/java/com/facebook/internal/Validate.java
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,8 @@ public static boolean hasCustomTabRedirectActivity(Context context) {
if (infos != null) {
for (ResolveInfo info : infos) {
ActivityInfo activityInfo = info.activityInfo;
if (activityInfo.name.equals(CustomTabActivity.class.getName())
&& activityInfo.packageName.equals(context.getPackageName())) {
if (activityInfo.name.equals(CustomTabActivity.class.getName()) &&
activityInfo.packageName.equals(context.getPackageName())) {
hasActivity = true;
} else {
// another application is listening for this url scheme, don't open
Expand Down
23 changes: 16 additions & 7 deletions facebook/src/main/java/com/facebook/login/DeviceAuthDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import android.content.DialogInterface;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.net.Uri;
import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;
Expand Down Expand Up @@ -55,11 +54,7 @@
import com.facebook.appevents.AppEventsLogger;
import com.facebook.devicerequests.internal.DeviceRequestsHelper;
import com.facebook.internal.AnalyticsEvents;
import com.facebook.internal.FetchedAppSettings;
import com.facebook.internal.FetchedAppSettingsManager;
import com.facebook.internal.ImageDownloader;
import com.facebook.internal.ImageRequest;
import com.facebook.internal.ImageResponse;
import com.facebook.internal.SmartLoginOption;
import com.facebook.internal.Utility;
import com.facebook.internal.Validate;
Expand All @@ -68,6 +63,7 @@
import org.json.JSONObject;

import java.util.Date;
import java.util.Locale;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
Expand All @@ -84,6 +80,7 @@ public class DeviceAuthDialog extends DialogFragment {

private ProgressBar progressBar;
private TextView confirmationCode;
private TextView instructions;
private DeviceAuthMethodHandler deviceAuthMethodHandler;
private AtomicBoolean completed = new AtomicBoolean();
private volatile GraphRequestAsyncTask currentGraphRequestPoll;
Expand Down Expand Up @@ -124,7 +121,6 @@ public View onCreateView(
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
dialog = new Dialog(getActivity(), R.style.com_facebook_auth_dialog);
LayoutInflater inflater = getActivity().getLayoutInflater();

View view = initializeContentView(DeviceRequestsHelper.isAvailable() && !this.isRetry);

Expand Down Expand Up @@ -216,6 +212,10 @@ public void onCompleted(GraphResponse response) {
private void setCurrentRequestState(RequestState currentRequestState) {
this.currentRequestState = currentRequestState;
confirmationCode.setText(currentRequestState.getUserCode());
final Bitmap bitmap =
DeviceRequestsHelper.generateQRCode(currentRequestState.getAuthorizationUri());
final BitmapDrawable qrCode = new BitmapDrawable(getResources(), bitmap);
instructions.setCompoundDrawablesWithIntrinsicBounds(null, qrCode, null, null);
confirmationCode.setVisibility(View.VISIBLE);
progressBar.setVisibility(View.GONE);

Expand Down Expand Up @@ -253,7 +253,7 @@ public void onClick(View v) {
}
});

TextView instructions = (TextView)view.findViewById(
instructions = (TextView) view.findViewById(
R.id.com_facebook_device_auth_instructions);
instructions.setText(
Html.fromHtml(getString(R.string.com_facebook_device_auth_instructions)));
Expand Down Expand Up @@ -460,19 +460,28 @@ private void onCancel() {
}

private static class RequestState implements Parcelable{
private String authorizationUri;
private String userCode;
private String requestCode;
private long interval;
private long lastPoll;

RequestState() {}

public String getAuthorizationUri() {
return authorizationUri;
}

public String getUserCode() {
return userCode;
}

public void setUserCode(String userCode) {
this.userCode = userCode;
this.authorizationUri = String.format(
Locale.ENGLISH,
"https://facebook.com/device?user_code=%1$s&qr=1",
userCode);
}

public String getRequestCode() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ public class BleScannerImpl implements BleScanner {

private static final String TAG = "BleScannerImpl";

private static final byte[] IBEACON_PREFIX = fromHexString("ff4c000215");
private static final byte[] EDDYSTONE_PREFIX = fromHexString("16aafe");
private static final byte[] GRAVITY_PREFIX = fromHexString("17ffab01");

private BluetoothAdapter bluetoothAdapter;
private BluetoothLeScanner bluetoothLeScanner;
private LocationPackageRequestParams params;
Expand Down Expand Up @@ -222,10 +226,14 @@ public void onScanResult(int callbackType, ScanResult result) {

private static BluetoothScanResult newBluetoothScanResult(ScanResult scanResult) {
ScanRecord scanRecord = scanResult.getScanRecord();
String payload = formatPayload(scanRecord.getBytes());
int rssi = scanResult.getRssi();
BluetoothScanResult bluetoothScanResult = new BluetoothScanResult(payload, rssi);
return bluetoothScanResult;
byte[] scanRecordBytes = scanRecord.getBytes();
if (isBeacon(scanRecordBytes)) {
String payload = formatPayload(scanRecord.getBytes());
int rssi = scanResult.getRssi();
BluetoothScanResult bluetoothScanResult = new BluetoothScanResult(payload, rssi);
return bluetoothScanResult;
}
return null;
}

private static String formatPayload(byte[] payload) {
Expand Down Expand Up @@ -269,4 +277,81 @@ private static void logException(String message, Exception e) {
Log.e(TAG, message, e);
}
}

private static boolean isBeacon(byte[] payload) {
if (payload == null) {
return false;
}
int startIndex = 0;
int payloadLength = payload.length;
while (startIndex < payloadLength) {
int advLengthField = payload[startIndex];
if (advLengthField <= 0) {
return false;
}
int advPacketLength = 1 + advLengthField;
if (startIndex + advPacketLength > payloadLength) {
return false;
}
if (isAdvPacketBeacon(payload, startIndex)) {
return true;
}
startIndex += advPacketLength;
}
return false;
}

private static boolean isAdvPacketBeacon(byte[] payload, int advStartIndex) {
if (isArrayContained(payload, advStartIndex + 1, IBEACON_PREFIX)) {
return true;
}
if (isArrayContained(payload, advStartIndex + 1, EDDYSTONE_PREFIX)) {
return true;
}
if (isArrayContained(payload, advStartIndex, GRAVITY_PREFIX)) {
return true;
}
if (isAltBeacon(payload, advStartIndex)) {
return true;
}
return false;
}

private static boolean isAltBeacon(byte[] payload, int startIndex) {
if (startIndex + 5 < payload.length) {
byte length = payload[startIndex];
byte packetType = payload[startIndex + 1];
byte beaconCode1 = payload[startIndex + 4];
byte beaconCode2 = payload[startIndex + 5];
return length == (byte) 0x1b
&& packetType == (byte) 0xff
&& beaconCode1 == (byte) 0xbe
&& beaconCode2 == (byte) 0xac;
}
return false;
}

private static boolean isArrayContained(byte[] array1, int startIndex1, byte[] array2) {
int length = array2.length;
if (startIndex1 + length > array1.length) {
return false;
}
for (int i = 0; i < length; i++) {
if (array1[startIndex1 + i] != array2[i]) {
return false;
}
}
return true;
}

private static byte[] fromHexString(String hexString) {
int len = hexString.length();
byte[] bytes = new byte[len / 2];
for (int i = 0; i < len; i += 2) {
bytes[i / 2] =
(byte) ((Character.digit(hexString.charAt(i), 16) << 4)
+ Character.digit(hexString.charAt(i + 1), 16));
}
return bytes;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
android:layout_marginStart="16dp"
android:layout_marginTop="20dp"
android:fontFamily="roboto_condensed"
android:gravity="center_horizontal"
android:gravity="center"
android:singleLine="false"
android:textColor="@color/com_facebook_device_auth_text"
android:textSize="12sp"
Expand All @@ -111,7 +111,9 @@
android:textColor="@color/com_facebook_device_auth_text"
android:textSize="10sp"
android:textStyle="bold"
android:typeface="sans" />
android:typeface="sans" >
<requestFocus />
</Button>
</FrameLayout>

</LinearLayout>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,10 @@
/>

<TextView
android:id="@+id/com_facebook_device_auth_instructions"
style="@style/com_facebook_auth_dialog_instructions_textview"
android:layout_marginTop="12dp"
/>
android:id="@+id/com_facebook_device_auth_instructions"
style="@style/com_facebook_auth_dialog_instructions_textview"
android:layout_marginTop="12dp"
/>

<FrameLayout
android:layout_width="match_parent"
Expand Down
2 changes: 0 additions & 2 deletions facebook/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
<string name="com_facebook_loginview_log_in_button_continue" gender="unknown">Continuer avec Facebook</string>
<string name="com_facebook_loginview_logged_in_as" gender="unknown">Connecté(e) en tant que : %1$s</string>
<string name="com_facebook_loginview_logged_in_using_facebook" gender="unknown">Connecté(e) avec Facebook</string>
<string name="com_facebook_loginview_logged_in_using_facebook_f1gender" gender="female">Connectée avec Facebook</string>
<string name="com_facebook_loginview_logged_in_using_facebook_m2gender" gender="male">Connecté avec Facebook</string>
<string name="com_facebook_loginview_log_out_action" gender="unknown">Déconnexion</string>
<string name="com_facebook_loginview_cancel_action" gender="unknown">Annuler</string>
<string name="com_facebook_loading" gender="unknown">Chargement...</string>
Expand Down
22 changes: 0 additions & 22 deletions facebook/src/main/res/values-iw/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,46 +7,24 @@
<string name="com_facebook_like_button_not_liked" gender="unknown">אהבתי</string>
<string name="com_facebook_like_button_liked" gender="unknown">אהבתי</string>
<string name="com_facebook_loginview_log_out_button" gender="unknown">התנתק/י</string>
<string name="com_facebook_loginview_log_out_button_f1gender" gender="female">התנתקי</string>
<string name="com_facebook_loginview_log_out_button_m2gender" gender="male">התנתק</string>
<string name="com_facebook_loginview_log_in_button" gender="unknown">התחבר</string>
<string name="com_facebook_loginview_log_in_button_long" gender="unknown">התחברות באמצעות פייסבוק</string>
<string name="com_facebook_loginview_log_in_button_continue" gender="unknown">המשך/המשיכי עם פייסבוק</string>
<string name="com_facebook_loginview_log_in_button_continue_f1gender" gender="female">המשיכי עם פייסבוק</string>
<string name="com_facebook_loginview_log_in_button_continue_m2gender" gender="male">המשך עם פייסבוק</string>
<string name="com_facebook_loginview_logged_in_as" gender="unknown">מחובר/ת בתור: %1$s</string>
<string name="com_facebook_loginview_logged_in_as_f1gender" gender="female">מחוברת בתור: %1$s</string>
<string name="com_facebook_loginview_logged_in_as_m2gender" gender="male">מחובר בתור: %1$s</string>
<string name="com_facebook_loginview_logged_in_using_facebook" gender="unknown">מחובר/ת כמשתמש בפייסבוק</string>
<string name="com_facebook_loginview_logged_in_using_facebook_f1gender" gender="female">מחוברת כמשתמש בפייסבוק</string>
<string name="com_facebook_loginview_logged_in_using_facebook_m2gender" gender="male">מחובר כמשתמש בפייסבוק</string>
<string name="com_facebook_loginview_log_out_action" gender="unknown">התנתק/י</string>
<string name="com_facebook_loginview_log_out_action_f1gender" gender="female">התנתקי</string>
<string name="com_facebook_loginview_log_out_action_m2gender" gender="male">התנתק</string>
<string name="com_facebook_loginview_cancel_action" gender="unknown">בטל</string>
<string name="com_facebook_loading" gender="unknown">טוען...</string>
<string name="com_facebook_internet_permission_error_title" gender="unknown">שגיאת AndroidManifest</string>
<string name="com_facebook_internet_permission_error_message" gender="unknown">התחברות WebView דורשת הרשאת אינטרנט</string>
<string name="com_facebook_tooltip_default" gender="unknown">את/ה בשליטה - בחר/י אילו פרטים ברצונך לשתף עם אפליקציות.</string>
<string name="com_facebook_tooltip_default_f1gender" gender="female">את בשליטה - בחרי אילו פרטים ברצונך לשתף עם אפליקציות.</string>
<string name="com_facebook_tooltip_default_m2gender" gender="male">אתה בשליטה - בחר אילו פרטים ברצונך לשתף עם אפליקציות.</string>
<string name="com_facebook_image_download_unknown_error" gender="unknown">שגיאה לא צפויה במהלך הורדת תמונה.</string>
<string name="com_facebook_share_button_text" gender="unknown">שתף/שתפי</string>
<string name="com_facebook_share_button_text_f1gender" gender="female">שתפי</string>
<string name="com_facebook_share_button_text_m2gender" gender="male">שתף</string>
<string name="com_facebook_send_button_text" gender="unknown">שלח/י</string>
<string name="com_facebook_send_button_text_f1gender" gender="female">שלחי</string>
<string name="com_facebook_send_button_text_m2gender" gender="male">שלח</string>
<string name="com_facebook_device_auth_instructions" gender="unknown">יש לבקר בכתובת facebook.com/device&lt;/b&amp;gt ולהזין את הקוד המוצג למעלה</string>
<string name="com_facebook_smart_device_instructions" gender="unknown">כדי לחבר את חשבונך, יש לפתוח את אפליקציית פייסבוק במכשיר הנייד ולבדוק אם יש התראות.</string>
<string name="com_facebook_smart_device_instructions_or" gender="unknown">- או -</string>
<string name="com_facebook_smart_login_confirmation_title" gender="unknown">אשר/י את ההתחברות</string>
<string name="com_facebook_smart_login_confirmation_title_f1gender" gender="female">אשרי את ההתחברות</string>
<string name="com_facebook_smart_login_confirmation_title_m2gender" gender="male">אשר את ההתחברות</string>
<string name="com_facebook_smart_login_confirmation_continue_as" gender="unknown">המשך/המשיכי בתור %1$s</string>
<string name="com_facebook_smart_login_confirmation_continue_as_f1gender" gender="female">המשיכי בתור %1$s</string>
<string name="com_facebook_smart_login_confirmation_continue_as_m2gender" gender="male">המשך בתור %1$s</string>
<string name="com_facebook_smart_login_confirmation_cancel" gender="unknown">לא את/ה?</string>
<string name="com_facebook_smart_login_confirmation_cancel_f1gender" gender="female">לא את?</string>
<string name="com_facebook_smart_login_confirmation_cancel_m2gender" gender="male">לא אתה?</string>
</resources>
Loading

0 comments on commit c491bb4

Please sign in to comment.