forked from mozilla/gecko-dev
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 1700795. Detect running from .dmg on macOS and report telemetry. …
…r=mstange,mossop Differential Revision: https://phabricator.services.mozilla.com/D121567
- Loading branch information
Showing
7 changed files
with
164 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5668,6 +5668,28 @@ startup: | |
record_in_processes: | ||
- main | ||
|
||
first_run_is_from_dmg: | ||
bug_numbers: | ||
- 1700795 | ||
description: > | ||
Recorded on first run of a Firefox install on macOS, with a boolean value | ||
indicating whether Firefox is being run directly from .dmg without | ||
installing, or not. Note if running from a .dmg we will get a new ping | ||
everytime the .dmg is remounted due to App Translocation. | ||
expires: "99" | ||
keyed: false | ||
kind: boolean | ||
notification_emails: | ||
- [email protected] | ||
- [email protected] | ||
operating_systems: | ||
- mac | ||
products: | ||
- 'firefox' | ||
record_in_processes: | ||
- 'main' | ||
release_channel_collection: opt-out | ||
|
||
script.preloader: | ||
mainthread_recompile: | ||
bug_numbers: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
// This file defines the interface between Cocoa-specific Obj-C++ and generic | ||
// C++, so it itself cannot have any Obj-C bits in it. | ||
|
||
#ifndef MacRunFromDmgUtils_h_ | ||
#define MacRunFromDmgUtils_h_ | ||
|
||
namespace mozilla { | ||
namespace MacRunFromDmgUtils { | ||
|
||
/** | ||
* Returns true if the app is running from the read-only filesystem of a | ||
* mounted .dmg. Returns false if not, or if we fail to determine whether it | ||
* is. | ||
*/ | ||
bool IsAppRunningFromDmg(); | ||
|
||
} // namespace MacRunFromDmgUtils | ||
} // namespace mozilla | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
#include <ApplicationServices/ApplicationServices.h> | ||
#include <CoreFoundation/CoreFoundation.h> | ||
#include <CoreServices/CoreServices.h> | ||
#include <IOKit/IOKitLib.h> | ||
#include <string.h> | ||
#include <sys/mount.h> | ||
#include <sys/param.h> | ||
|
||
#include "MacRunFromDmgUtils.h" | ||
|
||
#include "nsCocoaFeatures.h" | ||
#include "nsCommandLine.h" | ||
#include "nsCommandLineServiceMac.h" | ||
#include "nsILocalFileMac.h" | ||
#include "nsIMacDockSupport.h" | ||
#include "nsObjCExceptions.h" | ||
#include "nsString.h" | ||
|
||
// For IOKit docs, see: | ||
// https://developer.apple.com/documentation/iokit | ||
// https://developer.apple.com/library/archive/documentation/DeviceDrivers/Conceptual/IOKitFundamentals/ | ||
|
||
namespace mozilla { | ||
namespace MacRunFromDmgUtils { | ||
|
||
bool IsAppRunningFromDmg() { | ||
NS_OBJC_BEGIN_TRY_BLOCK_RETURN; | ||
|
||
const char* path = [[[NSBundle mainBundle] bundlePath] fileSystemRepresentation]; | ||
|
||
struct statfs statfsBuf; | ||
if (statfs(path, &statfsBuf) != 0) { | ||
return false; | ||
} | ||
|
||
// Optimization to minimize impact on startup time: | ||
if (!(statfsBuf.f_flags & MNT_RDONLY)) { | ||
return false; | ||
} | ||
|
||
// Get the "BSD device name" ("diskXsY", as found in /dev) of the filesystem | ||
// our app is on so we can use IOKit to get its IOMedia object: | ||
const char devDirPath[] = "/dev/"; | ||
const int devDirPathLength = strlen(devDirPath); | ||
if (strncmp(statfsBuf.f_mntfromname, devDirPath, devDirPathLength) != 0) { | ||
// Does this ever happen? | ||
return false; | ||
} | ||
const char* bsdDeviceName = statfsBuf.f_mntfromname + devDirPathLength; | ||
|
||
// Get the IOMedia object: | ||
// (Note: IOServiceGetMatchingServices takes ownership of serviceDict's ref.) | ||
CFMutableDictionaryRef serviceDict = IOBSDNameMatching(kIOMasterPortDefault, 0, bsdDeviceName); | ||
if (!serviceDict) { | ||
return false; | ||
} | ||
io_service_t media = IOServiceGetMatchingService(kIOMasterPortDefault, serviceDict); | ||
if (!media || !IOObjectConformsTo(media, "IOMedia")) { | ||
return false; | ||
} | ||
|
||
// Search the parent chain for a service implementing the disk image class | ||
// (taking care to start with `media` itself): | ||
io_service_t imageDrive = IO_OBJECT_NULL; | ||
io_iterator_t iter; | ||
if (IORegistryEntryCreateIterator(media, kIOServicePlane, | ||
kIORegistryIterateRecursively | kIORegistryIterateParents, | ||
&iter) != KERN_SUCCESS) { | ||
IOObjectRelease(media); | ||
return false; | ||
} | ||
const char* imageClass = | ||
nsCocoaFeatures::macOSVersionMajor() >= 12 ? "AppleDiskImageDevice" : "IOHDIXHDDrive"; | ||
for (imageDrive = media; imageDrive; imageDrive = IOIteratorNext(iter)) { | ||
if (IOObjectConformsTo(imageDrive, imageClass)) { | ||
break; | ||
} | ||
IOObjectRelease(imageDrive); | ||
} | ||
IOObjectRelease(iter); | ||
|
||
if (imageDrive) { | ||
IOObjectRelease(imageDrive); | ||
return true; | ||
} | ||
return false; | ||
|
||
NS_OBJC_END_TRY_BLOCK_RETURN(false); | ||
} | ||
|
||
} // namespace MacRunFromDmgUtils | ||
} // namespace mozilla |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters